added async process opening

This commit is contained in:
petrucci4prez 2018-08-25 23:07:05 -04:00
parent 23d3c170d4
commit a7591e9189
1 changed files with 17 additions and 9 deletions

View File

@ -478,9 +478,13 @@ Keeping confirmation enabled does weird stuff with helm. Not ideal at the moment
(start-process "" nil "xdg-open" f))) (start-process "" nil "xdg-open" f)))
file-list)))) file-list))))
(defun nd/execute-desktop-command (cmd file)
"Opens FILE using CMD in separate process."
(call-process-shell-command (concat (replace-regexp-in-string "%[fuFU]" file cmd t) " &")))
(defun nd/dired-open-with () (defun nd/dired-open-with ()
"Open marked non-text files in external app via open-with dialog "Open marked non-text files in external app via open-with dialog
according to mime types as listed in all available desktop files.mimetype" according to mime types as listed in all available desktop files"
(interactive) (interactive)
(let* ((file-list (let* ((file-list
(mapcar (mapcar
@ -488,14 +492,18 @@ according to mime types as listed in all available desktop files.mimetype"
"\n\\'" "" "\n\\'" ""
(shell-command-to-string (concat "file --mime-type -b " f))))) (shell-command-to-string (concat "file --mime-type -b " f)))))
(seq-filter #'file-regular-p (dired-get-marked-files))))) (seq-filter #'file-regular-p (dired-get-marked-files)))))
(if (= (length file-list) 1) (cond
(let* ((file-pair (car file-list)) ((= (length file-list) 0)
(file-name (nth 0 file-pair)) (message "No suitable programs found"))
(mime-alist (nd/get-apps-from-mime (nth 1 file-pair)))) ((= (length file-list) 1)
(helm :sources (helm-build-sync-source "Apps" (let* ((file-pair (car file-list))
:candidates mime-alist (file-name (nth 0 file-pair))
:action '(("Open" . (lambda (f) (shell-command (replace-regexp-in-string "%[fuFU]" file-name f t)))))) (mime-alist (nd/get-apps-from-mime (nth 1 file-pair))))
:buffer "*helm open with*"))))) (helm :sources
(helm-build-sync-source "Apps"
:candidates mime-alist
:action '(("Open" . (lambda (f) (nd/execute-desktop-command f file-name)))))
:buffer "*helm open with*"))))))
#+END_SRC #+END_SRC
* org-mode * org-mode
** major mode ** major mode