-
Notifications
You must be signed in to change notification settings - Fork 0
/
FCT-switch-to-OS-explorer.el
51 lines (49 loc) · 2.09 KB
/
FCT-switch-to-OS-explorer.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
;;; open-file-or-directory-in-external-app
(defun brice-open-file-or-directory-in-external-app ()
"Open the current file or dired marked files in external app.
The app is chosen from your OS's preference.
URL 'http://ergoemacs.org/emacs/emacs_dired_open_file_in_ext_apps.html'
Version 2016-10-15"
(interactive)
(let* (
($file-list
(if (string-equal major-mode "dired-mode")
(dired-get-marked-files)
(list (buffer-file-name))))
($do-it-p (if (<= (length $file-list) 5)
t
(y-or-n-p "Open more than 5 files? "))))
(when $do-it-p
(cond
((string-equal system-type "windows-nt")
(mapc
(lambda ($fpath)
(w32-shell-execute "open" (replace-regexp-in-string "/" "\\" $fpath t t))) $file-list))
((string-equal system-type "darwin")
(mapc
(lambda ($fpath)
(shell-command
(concat "open " (shell-quote-argument $fpath)))) $file-list))
((string-equal system-type "gnu/linux")
(mapc
(lambda ($fpath) (let ((process-connection-type nil))
(start-process "" nil "xdg-open" $fpath))) $file-list))))))
;;; open-directory-with-explorer
(defun brice-open-directory-with-explorer ()
"Show current file in desktop (OS's file manager).
URL `http://ergoemacs.org/emacs/emacs_dired_open_file_in_ext_apps.html'
Version 2015-11-30"
(interactive)
(cond
((string-equal system-type "windows-nt")
(w32-shell-execute "explore" (replace-regexp-in-string "/" "\\" default-directory t t)))
((string-equal system-type "darwin") (shell-command "open ."))
((string-equal system-type "gnu/linux")
(let (
(process-connection-type nil)
(openFileProgram (if (file-exists-p "/usr/bin/gvfs-open")
"/usr/bin/gvfs-open"
"/usr/bin/xdg-open")))
(start-process "" nil openFileProgram "."))
;; (shell-command "xdg-open .") ;; 2013-02-10 this sometimes froze emacs till the folder is closed. For example: with nautilus
)))