summaryrefslogtreecommitdiff
path: root/.config/nyxt/commands.lisp
diff options
context:
space:
mode:
Diffstat (limited to '.config/nyxt/commands.lisp')
-rw-r--r--.config/nyxt/commands.lisp65
1 files changed, 65 insertions, 0 deletions
diff --git a/.config/nyxt/commands.lisp b/.config/nyxt/commands.lisp
new file mode 100644
index 0000000..4c762f8
--- /dev/null
+++ b/.config/nyxt/commands.lisp
@@ -0,0 +1,65 @@
+(defvar *thanos/search-engines*
+ (list
+ '("google" "https://google.com/search?q=~a")
+ '("aa" "https://annas-archive.org/search?q=~a")
+ '("v" "https://yewtu.be/search?q=~a")
+ '("duck" "https://duckduckgo.com/?q=~a"))
+ "List of search engines.")
+
+(define-command-global thanos/set-url ()
+ "Lean & Mean version of thanos/set-url
+
+Default set-url does way too much for my liking and occasionally
+hangs, this is just a minimal alternative"
+ (let* ((prompt-result (first
+ (prompt
+ :prompt "Search"
+ :sources (list (make-instance 'prompter:raw-source))))))
+ (cond
+ ((and (or (str:ends-with-p ".org" prompt-result)
+ (str:ends-with-p ".com" prompt-result)
+ (str:ends-with-p ".net" prompt-result)
+ (str:ends-with-p ".engineer" prompt-result))
+ (not (find #\Space prompt-result)))
+ (buffer-load (str:concat "https://" prompt-result)))
+ ((str:starts-with-p "localhost" prompt-result)
+ (buffer-load (str:concat "http://" prompt-result)))
+ ((let ((split-result (str:split #\Space prompt-result)))
+ (find (first split-result) *thanos/search-engines* :key #'first :test #'string=))
+ (let* ((engine-tag (subseq prompt-result 0 (position #\Space prompt-result)))
+ (query (subseq prompt-result (+ 1 (position #\Space prompt-result))))
+ (engine (find engine-tag *thanos/search-engines* :key #'first :test #'string=))
+ (search-url (second engine)))
+ (buffer-load (cl-ppcre:regex-replace "~a" search-url (quri:url-encode query)))))
+ (t
+ (let* ((engine (first (last *thanos/search-engines*)))
+ (search-url (second engine)))
+ (buffer-load (cl-ppcre:regex-replace "~a" search-url (quri:url-encode prompt-result))))))))
+
+
+(define-command-global thanos/set-url-new-buffer ()
+ "Lean & Mean version of thanos/set-url-new-buffer"
+ (let* ((prompt-result (first
+ (prompt
+ :prompt "Search"
+ :sources (list (make-instance 'prompter:raw-source))))))
+ (cond
+ ((and (or (str:ends-with-p ".org" prompt-result)
+ (str:ends-with-p ".com" prompt-result)
+ (str:ends-with-p ".net" prompt-result)
+ (str:ends-with-p ".engineer" prompt-result))
+ (not (find #\Space prompt-result)))
+ (make-buffer-focus :url (str:concat "https://" prompt-result)))
+ ((str:starts-with-p "localhost" prompt-result)
+ (make-buffer-focus :url (str:concat "http://" prompt-result)))
+ ((let ((split-result (str:split #\Space prompt-result)))
+ (find (first split-result) *thanos/search-engines* :key #'first :test #'string=))
+ (let* ((engine-tag (subseq prompt-result 0 (position #\Space prompt-result)))
+ (query (subseq prompt-result (+ 1 (position #\Space prompt-result))))
+ (engine (find engine-tag *thanos/search-engines* :key #'first :test #'string=))
+ (search-url (second engine)))
+ (make-buffer-focus :url (cl-ppcre:regex-replace "~a" search-url (quri:url-encode query)))))
+ (t
+ (let* ((engine (first (last *thanos/search-engines*)))
+ (search-url (second engine)))
+ (make-buffer-focus :url (cl-ppcre:regex-replace "~a" search-url (quri:url-encode prompt-result))))))))