commit fe25203bad7e9b44e7c931c4aca0f6c8e682c157 parent 3a577b71d89b90dcb5505aea8650f84275d6dd96 Author: Daniel Barlow <dan@telent.net> Date: Tue, 17 Jan 2023 11:03:30 +0000 proof of concept search command Diffstat:
| M | command.fnl | | | 29 | +++++++++++++++++++++++++++++ |
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/command.fnl b/command.fnl @@ -69,6 +69,35 @@ #$1.buffer.name]] (fn [{: buffer}] (buffer:back))) +(fn url-escape [s] + (string.gsub s + "([^A-Za-z0-9_])" + #(string.format "%%%02x" (string.byte $1)))) + +(local searchers { + :ddg (fn [term] + (.. "https://duckduckgo.com/?q=" (url-escape term))) + }) + + +(define-command + "search" + [[:term + #[(completion {:text $1})] + #""] + [:buffer + #(lume.map (Buffer.match $1) #(completion { :text $1.name :value $1 })) + #$1.buffer.name] + [:engine + #[(completion {:text "Duck Duck Go" :value :ddg}) + (completion {:text "Google" :value :google}) + (completion {:text "Luai (yoyo.org)" :value :luai})] + #"Duck Duck Go"]] + (fn [{: term : engine : buffer}] + (buffer:visit ((. searchers engine) term)))) + + + (fn find-command [name] (. commands name))