proof of concept search command
This commit is contained in:
parent
3a577b71d8
commit
fe25203bad
29
command.fnl
29
command.fnl
@ -69,6 +69,35 @@
|
|||||||
#$1.buffer.name]]
|
#$1.buffer.name]]
|
||||||
(fn [{: buffer}] (buffer:back)))
|
(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]
|
(fn find-command [name]
|
||||||
(. commands name))
|
(. commands name))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user