SHARE
TWEET

Untitled

a guest Feb 24th, 2018 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; Make dired open certain file types externally when pressing RET on a file.
  2. (defvar unsupported-mime-types
  3.   '("application/pdf"
  4.     "image/png"
  5.     "image/jpeg"
  6.     "image/x-xcf"))
  7.  
  8. (load "subr-x")
  9.  
  10. (defun get-mimetype (filepath)
  11.   (string-trim
  12.    (shell-command-to-string (concat "file -b --mime-type " filepath))))
  13.  
  14. (defun dired-find-file-dwim ()
  15.   (interactive)
  16.   (let ((file (dired-get-filename nil t)))
  17.     (if (member (get-mimetype file) unsupported-mime-types)
  18.       (call-process "xdg-open" nil 0 nil file)
  19.       (find-file file))))
  20.  
  21. (with-eval-after-load 'dired
  22.   (define-key dired-mode-map (kbd "RET") #'dired-find-file-dwim))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top