Commit 5c9315b2 authored by Juri Linkov's avatar Juri Linkov
Browse files

* lisp/dired-aux.el (dired-do-open): New command (bug#18132).

* lisp/dired.el (dired-context-menu): Bind 'dired-do-open' to "Open".

* lisp/dired-aux.el (shell-command-guess-xdg): Use 'shell-quote-argument'.
parent 6227ea0e
Pipeline #27401 failed with stage
in 3 minutes and 7 seconds
......@@ -511,6 +511,10 @@ based on marked files in Dired. Possible backends are
and a universal command such as "open" or "start"
that delegates to the OS.
*** New command 'dired-do-open'.
Bound to the context menu "Open", delegates opening the marked files
to the OS.
** Ediff
---
......
......@@ -1367,7 +1367,8 @@ after adding own commands to the composite list."
(let* ((xdg-mime (when (executable-find "xdg-mime")
(string-trim-right
(shell-command-to-string
(concat "xdg-mime query filetype " (car files))))))
(concat "xdg-mime query filetype "
(shell-quote-argument (car files)))))))
(xdg-mime-apps (unless (string-empty-p xdg-mime)
(xdg-mime-apps xdg-mime)))
(xdg-commands
......@@ -1401,6 +1402,39 @@ after adding own commands to the composite list."
"Populate COMMANDS by the `open' command."
(append (ensure-list shell-command-guess-open) commands))
(declare-function w32-shell-execute "w32fns.c")
(defun dired-do-open (&optional arg)
"Open the marked files or a file at click/point externally.
If files are marked, run the command from `shell-command-guess-open'
on each of marked files. Otherwise, run it on the file where
the mouse is clicked, or on the file at point."
(interactive "P" dired-mode)
(let ((files (if (mouse-event-p last-nonmenu-event)
(save-excursion
(mouse-set-point last-nonmenu-event)
(dired-get-marked-files nil arg))
(dired-get-marked-files nil arg)))
(command shell-command-guess-open))
(when (and (memq system-type '(windows-nt))
(equal command "start"))
(setq command "open"))
(when command
(dolist (file files)
(cond
((memq system-type '(gnu/linux))
(call-process command nil 0 nil file))
((memq system-type '(ms-dos))
(shell-command (concat command " " (shell-quote-argument file))))
((memq system-type '(windows-nt))
(w32-shell-execute command (convert-standard-filename file)))
((memq system-type '(cygwin))
(call-process command nil nil nil file))
((memq system-type '(darwin))
(start-process (concat command " " file) nil command file))
(t
(error "Open not supported on this system")))))))
;;; Commands that delete or redisplay part of the dired buffer
......
......@@ -2591,6 +2591,9 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
["Delete Image Tag..." image-dired-delete-tag
:help "Delete image tag from current or marked files"]))
(declare-function shell-command-guess "dired-aux" (files))
(defvar shell-command-guess-open)
(defun dired-context-menu (menu click)
"Populate MENU with Dired mode commands at CLICK."
(when (mouse-posn-property (event-start click) 'dired-filename)
......@@ -2606,6 +2609,9 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
:help "Edit file at mouse click"]
["Find in Other Window" dired-mouse-find-file-other-window
:help "Edit file at mouse click in other window"]
,@(when shell-command-guess-open
'(["Open" dired-do-open
:help "Open externally"]))
,@(when commands
(list (cons "Open With"
(append
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment