eufon

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d831ccbb67e0deb049bb5f48b811529d98b71d51
parent 5871afe19735a3e8e1a8c6dc2aeb0c92293aae4c
Author: Daniel Barlow <dan@telent.net>
Date:   Wed,  9 Mar 2022 23:30:23 +0000

add DWIMminess to url bar text entry

- prepend https:// to things that might be partial URLs
- perform searches for things that are not URLs (e.g. contain spaces)
- use different search engines for things that start with @foo

e.g. @ebay, @ddg, @lua

Diffstat:
Mjust/just.fnl | 26+++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/just/just.fnl b/just/just.fnl @@ -40,6 +40,30 @@ progress, trough { name (or size Gtk.IconSize.LARGE_TOOLBAR))) +(fn urlencode [url] + (-> url + (: :gsub "([^%w ])" (fn [c] (string.format "%%%02X" (string.byte c)))) + (: :gsub " " "+"))) + +(print (urlencode "hello world o'hare & feirneds")) + +(local default-search-provider "ddg") + +(fn search-term-to-uri [provider text] + (match provider + "ebay" (.. "https://www.ebay.co.uk/sch/i.html?_nkw=" (urlencode text)) + "lua" (.. "https://pgl.yoyo.org/luai/i/" (urlencode text)) + "ddg" (.. "https://duckduckgo.com/?q=" (urlencode text)))) + +(fn to-uri [text] + (if (text:find " ") + (let [(_ _ provider term) (text:find "^@(%g+) *(.*)")] + (if provider + (search-term-to-uri provider term) + (search-term-to-uri default-search-provider text))) + (text:find "^http") text + (.. "https://" text))) + (local Navbar { @@ -48,7 +72,7 @@ progress, trough { (let [url (Gtk.Entry { ;; :completion (Gtk.EntryCompletion {:model completions :text_column 0 }) :on_activate - #(webview:visit $1.text) + #(webview:visit (to-uri $1.text)) }) stop (doto (Gtk.Button { :on_clicked #(webview:stop-loading)