diff --git a/command.fnl b/command.fnl index 3396a21..e8ee304 100644 --- 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))