summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-01-31 13:05:04 +0200
committerThanos Apollo <[email protected]>2024-01-31 13:05:04 +0200
commitd67e5585467cd2b1f309f211ee0c43c36916d8ca (patch)
tree5e1bb7035e8a7f0eb92543e8e56b89b16ac76eb1
parent9a9b74e6cc4f19cc233f4672755b950572a5d524 (diff)
nyxt: Add commands.lisp
-rw-r--r--.config/nyxt/commands.lisp65
-rw-r--r--.config/nyxt/config.lisp2
2 files changed, 66 insertions, 1 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))))))))
diff --git a/.config/nyxt/config.lisp b/.config/nyxt/config.lisp
index 898fe4c..d7c8ca5 100644
--- a/.config/nyxt/config.lisp
+++ b/.config/nyxt/config.lisp
@@ -17,7 +17,7 @@ Extension files (like dark-reader.lisp) are to append to this list.
Why the variable? Because it's too much hassle copying it everywhere.")
(define-nyxt-user-system-and-load nyxt-user/basic-config
- :components ("keybinds" "colorscheme"))
+ :components ("keybinds" "colorscheme" "commands"))
(define-configuration (:modable-buffer :prompt-buffer :editor-buffer)