FIX exe search on missing app directory

This commit is contained in:
Nathan Dwarshuis 2021-02-18 15:19:16 -05:00
parent 78f6d2bf70
commit 22fc7a4bdd
1 changed files with 13 additions and 19 deletions

View File

@ -192,25 +192,19 @@ OS is one of those in `system-type'."
(defun nd/get-apps-from-mime (mimetype) (defun nd/get-apps-from-mime (mimetype)
"Return all applications that can open a given MIMETYPE. "Return all applications that can open a given MIMETYPE.
The list is comprised of alists where pairs are of the form (name . command)." The list is comprised of alists where pairs are of the form (name . command)."
(let* ((case-fold-search nil) (let ((case-fold-search nil)
(mime-regex (concat "^MimeType=.*" mimetype ";?.*$")) (mime-regex (format "^MimeType=.*%s;?.*$" mimetype)))
(desktop-dirs '("/usr/share/applications" (->> (list "/usr/share/applications"
"/usr/local/share/applications" "/usr/local/share/applications"
"~/.local/share/applications")) "~/.local/share/applications")
(desktop-files (mapcan (lambda (d) (directory-files d t ".*\\.desktop" t)) desktop-dirs)) (-filter #'f-exists-p)
(app-list)) (--mapcat (directory-files it t ".*\\.desktop" t))
(dolist (file desktop-files app-list) (--map (let ((tb (f-read-text it 'utf-8)))
(with-temp-buffer (when (s-match mime-regex tb)
(insert-file-contents file) (let ((exec (cadr (s-match "^Exec=\\(.*\\)$" tb))))
(let* ((tb (buffer-string))) (-> (or (cadr (s-match "^Name=\\(.*\\)$" tb)) exec)
(if (string-match mime-regex tb) (cons exec))))))
(let* ((exec (progn (string-match "^Exec=\\(.*\\)$" tb) (-non-nil))))
(match-string 1 tb)))
(name (or
(progn (string-match "^Name=\\(.*\\)$" tb)
(match-string 1 tb))
exec)))
(setq app-list (cons `(,name . ,exec) app-list)))))))))
(defun nd/get-apps-bulk-from-mime (mimetype) (defun nd/get-apps-bulk-from-mime (mimetype)
"Like `nd/get-apps-from-mime' but only includes apps that can open "Like `nd/get-apps-from-mime' but only includes apps that can open