summaryrefslogtreecommitdiff
path: root/.config/nyxt/commands.lisp
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-02-27 14:53:14 +0200
committerThanos Apollo <[email protected]>2024-02-27 14:53:14 +0200
commit04e0b9a5d0b400870e6ca39f454e7ed388ffe0af (patch)
tree4edeb5238688397a18196474cdfc2df83ea8c90c /.config/nyxt/commands.lisp
parent67ac84114a5a510a3b5a738e48e03c54a7bdc58c (diff)
nyxt: Rewrite modules
Diffstat (limited to '.config/nyxt/commands.lisp')
-rw-r--r--.config/nyxt/commands.lisp63
1 files changed, 0 insertions, 63 deletions
diff --git a/.config/nyxt/commands.lisp b/.config/nyxt/commands.lisp
deleted file mode 100644
index 1739793..0000000
--- a/.config/nyxt/commands.lisp
+++ /dev/null
@@ -1,63 +0,0 @@
-(in-package #:nyxt-user)
-
-(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")
- '("aw" "https://wiki.archlinux.org/index.php?search=~a")
- '("duck" "https://duckduckgo.com/?q=~a"))
- "List of search engines.
-Last entry is the default.")
-
-(defun direct-url-p (url)
- "Checks if `url` is a direct URL with specific extensions, returning
-t if so and nil otherwise. The URL must not contain spaces."
- (not (null (or (and (null (cl-ppcre:scan "\\s" url))
- (or (cl-ppcre:scan "^(https?://)?.*\\.org(\\/.*)?$" url)
- (cl-ppcre:scan "^(https?://)?.*\\.com(\\/.*)?$" url)
- (cl-ppcre:scan "^(https?://)?.*\\.net(\\/.*)?$" url)
- (cl-ppcre:scan "^(https?://)?.*\\.gr(\\/.*)?$" url)
- (cl-ppcre:scan "^(https?://)?.*\\.co(\\/.*)?$" url)
- (cl-ppcre:scan "^(https?://)?.*\\.engineer(\\/.*)?$" url)))))))
-
-(defun handle-url (query func)
- "Process `query` as a URL or search query.
-
-Applies `func` to the query`.
-Requires the variable `*thanos/search-engines*` for search queries."
- (cond
- ((or (str:starts-with-p "localhost" query))
- (funcall func (str:concat "http://" query)))
- ((direct-url-p query)
- (funcall func (str:concat "https://" query)))
- ((str:starts-with-p "http" query)
- (funcall func query))
- ((let ((split-result (str:split #\Space query)))
- (find (first split-result) *thanos/search-engines* :key #'first :test #'string=))
- (let* ((engine-tag (subseq query 0 (position #\Space query)))
- (query (subseq query (+ 1 (position #\Space query))))
- (engine (find engine-tag *thanos/search-engines* :key #'first :test #'string=))
- (search-url (second engine)))
- (funcall func (cl-ppcre:regex-replace "~a" search-url (quri:url-encode query)))))
- (t
- (let* ((engine (first (last *thanos/search-engines*)))
- (search-url (second engine)))
- (funcall func (cl-ppcre:regex-replace "~a" search-url (quri:url-encode query)))))))
-
-(defun thanos/make-buffer-focus-url (url)
- (make-buffer-focus :url url))
-
-(define-command-global thanos/set-url ()
- (let* ((prompt-result (first
- (prompt
- :prompt "Search"
- :sources (list (make-instance 'prompter:raw-source))))))
- (handle-url prompt-result 'buffer-load)))
-
-(define-command-global thanos/set-url-new-buffer ()
- (let* ((prompt-result (first
- (prompt
- :prompt "Search [New Buffer]"
- :sources (list (make-instance 'prompter:raw-source))))))
- (handle-url prompt-result 'thanos/make-buffer-focus-url)))