From 7d687a0d7b9274acb644f016ae2fd17bd95ec481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Antol=C3=ADn=20Camarena?= Date: Sun, 6 Dec 2020 15:09:25 -0600 Subject: [PATCH] Add function to open file in operating system's default application (#38) --- consult.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/consult.el b/consult.el index b3d5ae59..405b8942 100644 --- a/consult.el +++ b/consult.el @@ -592,6 +592,20 @@ This command obeys narrowing. Optionally INITIAL input can be provided." (interactive) (find-file-other-window (consult--recent-file-read))) +;;;###autoload +(defun consult-open-externally (file) + "Open FILE using system's default application." + (interactive "fOpen: ") + (if (and (eq system-type 'windows-nt) + (fboundp 'w32-shell-execute)) + (w32-shell-execute "open" target) + (call-process (pcase system-type + ('darwin "open") + ('cygwin "cygstart") + (_ "xdg-open")) + nil 0 nil + (expand-file-name file)))) + ;; Use minibuffer completion as the UI for completion-at-point (defun consult-completion-in-region (start end collection &optional predicate) "Prompt for completion of region in the minibuffer if non-unique.