proof of concept search command

main
Daniel Barlow 2023-01-17 11:03:30 +00:00
parent 3a577b71d8
commit fe25203bad
1 changed files with 29 additions and 0 deletions

View File

@ -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))