Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Make dired open certain file types externally when pressing RET on a file.
- (defvar unsupported-mime-types
- '("application/pdf"
- "image/png"
- "image/jpeg"
- "image/x-xcf"))
- (load "subr-x")
- (defun get-mimetype (filepath)
- (string-trim
- (shell-command-to-string (concat "file -b --mime-type " filepath))))
- (defun dired-find-file-dwim ()
- (interactive)
- (let ((file (dired-get-filename nil t)))
- (if (member (get-mimetype file) unsupported-mime-types)
- (call-process "xdg-open" nil 0 nil file)
- (find-file file))))
- (with-eval-after-load 'dired
- (define-key dired-mode-map (kbd "RET") #'dired-find-file-dwim))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement