From 8b50eec3beaf5340e7831c982a0bc28758694290 Mon Sep 17 00:00:00 2001 From: cage Date: Sun, 28 Mar 2021 14:33:56 +0200 Subject: [PATCH] - [gemini] allowed exploring directory using relative path; - [gemini] allowed opening a file using tinmop itself (example: opening a gemini text file); - added a more hi-level function to open a file with an external program. - this function takes into account the file that should be opened with tinmop and uses 'xdg-open' as fallback if the user did not specified an association program file-type. --- etc/shared.conf | 4 ++++ src/filesystem-utils.lisp | 10 ++++++++++ src/open-attach-window.lisp | 4 +--- src/open-message-link-window.lisp | 28 ++++++++++------------------ src/os-utils.lisp | 13 +++++++++++++ src/package.lisp | 8 ++++++-- src/program-events.lisp | 2 +- src/software-configuration.lisp | 3 +++ 8 files changed, 48 insertions(+), 24 deletions(-) diff --git a/etc/shared.conf b/etc/shared.conf index 51df477..af398b4 100644 --- a/etc/shared.conf +++ b/etc/shared.conf @@ -173,3 +173,7 @@ color-regexp = ":rendering" cyan # open png files with gimp but cache them before # ▼▼▼▼▼▼▼▼▼ # open "https?://png$" with "gimp" use cache +# if you want to open some kind of file with tinmop try the following +# valid values are "tinmop" "me" "internal" +# ▼▼▼▼▼▼▼▼ +open "gmi$" with "tinmop" \ No newline at end of file diff --git a/src/filesystem-utils.lisp b/src/filesystem-utils.lisp index 9950e06..f051085 100644 --- a/src/filesystem-utils.lisp +++ b/src/filesystem-utils.lisp @@ -133,6 +133,16 @@ (setf all-paths (sort all-paths #'string<)) all-paths)) +(defgeneric prepend-pwd (object)) + +(defmethod prepend-pwd ((object string)) + (if (cl-ppcre:scan "^\\." object) + (text-utils:strcat (os-utils:pwd) *directory-sep* object) + object)) + +(defmethod prepend-pwd ((object sequence)) + (map 'list #'prepend-pwd object)) + (defun search-matching-file (root-directory &key (name ".*")) "Scan a filesystem saving files that match the provided criteria, does not follow symlinks." diff --git a/src/open-attach-window.lisp b/src/open-attach-window.lisp index 6d75b28..492fdfe 100644 --- a/src/open-attach-window.lisp +++ b/src/open-attach-window.lisp @@ -136,6 +136,4 @@ (progn (db:cache-invalidate url) (open-attachment url)) - (if program - (os-utils:open-link-with-program program url) - (os-utils:xdg-open cached-file))))))))) + (os-utils:open-resource-with-external-program url nil)))))))) diff --git a/src/open-message-link-window.lisp b/src/open-message-link-window.lisp index 45395fa..d7950e4 100644 --- a/src/open-message-link-window.lisp +++ b/src/open-message-link-window.lisp @@ -73,25 +73,17 @@ (defun open-message-link (url enqueue) (let* ((parsed (iri:iri-parse url)) (scheme (uri:scheme parsed))) - (cond - ((string= gemini-constants:+gemini-scheme+ scheme) + (if (string= gemini-constants:+gemini-scheme+ scheme) (let ((program-events:*process-events-immediately* t) - (event (make-instance 'program-events:gemini-push-behind-downloading-event - :priority program-events:+maximum-event-priority+))) - (db:insert-in-history (ui:gemini-open-url-prompt) url) - (db:gemlog-mark-as-seen url) - (gemini-viewer:ensure-just-one-stream-rendering) - (program-events:push-event event)) - (gemini-viewer:request url :enqueue enqueue - :use-cached-file-if-exists t)) - ((null scheme) - (gemini-viewer:load-gemini-url url - :give-focus-to-message-window nil)) - (t - (let ((program (swconf:link-regex->program-to-use url))) - (if program - (os-utils:open-link-with-program program url) - (os-utils:xdg-open url))))))) + (event (make-instance 'program-events:gemini-push-behind-downloading-event + :priority program-events:+maximum-event-priority+))) + (db:insert-in-history (ui:gemini-open-url-prompt) url) + (db:gemlog-mark-as-seen url) + (gemini-viewer:ensure-just-one-stream-rendering) + (program-events:push-event event) + (gemini-viewer:request url :enqueue enqueue + :use-cached-file-if-exists t)) + (os-utils:open-resource-with-external-program url nil)))) (defclass open-links-window () ((links diff --git a/src/os-utils.lisp b/src/os-utils.lisp index 07d98d2..b154d4d 100644 --- a/src/os-utils.lisp +++ b/src/os-utils.lisp @@ -56,6 +56,9 @@ (or (os-utils:getenv "TMPDIR") "/tmp/")) +(defun pwd () + (os-utils:getenv "PWD")) + (defun external-editor () (let ((error-message (_ "No editor found, please configure the 'editor' directive in your configuration file")) @@ -132,3 +135,13 @@ :wait nil :output nil :error :output))) + +(defun open-resource-with-external-program (resource give-focus-to-message-window) + (let ((program (swconf:link-regex->program-to-use resource))) + (if program + (if (swconf:use-tinmop-as-external-program-p program) + (gemini-viewer:load-gemini-url resource + :give-focus-to-message-window + give-focus-to-message-window) + (os-utils:open-link-with-program program resource)) + (os-utils:xdg-open resource)))) diff --git a/src/package.lisp b/src/package.lisp index 8f6dad6..99531ab 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -279,6 +279,7 @@ :add-extension :do-directory :collect-children + :prepend-pwd :search-matching-file :regular-file-p :dirp @@ -327,15 +328,17 @@ :+ssl-key-name+ :cpu-number :xdg-open - :open-link-with-program :getenv :default-temp-dir + :pwd :open-with-editor :exit-program :user-cache-dir :cached-file-path :generate-ssl-certificate - :send-to-pipe)) + :send-to-pipe + :open-link-with-program + :open-resource-with-external-program)) (defpackage :text-utils (:use @@ -1127,6 +1130,7 @@ :config-password-echo-character :config-win-focus-mark :link-regex->program-to-use + :use-tinmop-as-external-program-p :thread-message-symbol :thread-message-read-colors :thread-message-unread-colors diff --git a/src/program-events.lisp b/src/program-events.lisp index 863af43..95fc7ad 100644 --- a/src/program-events.lisp +++ b/src/program-events.lisp @@ -1017,7 +1017,7 @@ ((gemini-client:absolute-gemini-url-p url) (gemini-viewer:request url :use-cached-file-if-exists use-cached-file-if-exists)) ((fs:dirp url) - (let* ((all-paths (fs:collect-children url)) + (let* ((all-paths (fs:prepend-pwd (fs:collect-children url))) (raw-text (with-output-to-string (stream) (write-sequence (gemini-parser:geminize-h1 (format nil diff --git a/src/software-configuration.lisp b/src/software-configuration.lisp index 1c48b49..2aea30e 100644 --- a/src/software-configuration.lisp +++ b/src/software-configuration.lisp @@ -811,6 +811,9 @@ (values (program-name found) (use-cache-p found)))) +(defun use-tinmop-as-external-program-p (program) + (cl-ppcre:scan "(^me$)|(^internal$)|(tinmop)" program)) + (defun config-win-focus-mark () (values (access:accesses *software-configuration* +key-window+