add the ability to open external apps from dired

This commit is contained in:
Chris Cochrun 2021-03-17 13:43:35 -05:00
parent 784f8413d2
commit aa13c8e774
3 changed files with 22 additions and 6 deletions

View file

@ -537,17 +537,25 @@ I do a lot of docker management so having yaml is necessary
** File Management ** File Management
*** Dired *** Dired
I'm making a small function in here to open files in the appropriate program using XDG defaults. This is like opening odt files in Libreoffice or mp4 files in MPV.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package dired (use-package dired
:ensure nil :ensure nil
:straight nil :straight nil
:config
(defun chris/dired-open-xdg ()
"Open the file-at-point in the appropriate program"
(interactive)
(let ((file (ignore-errors (dired-get-file-for-visit))))
(browse-url (file-truename file))))
:general :general
(chris/leader-keys (chris/leader-keys
:states 'normal :states 'normal
:keymaps 'override :keymaps 'override
"od" '(dired-jump :which-key "open dired here")) "od" '(dired-jump :which-key "open dired here"))
(general-def 'normal dired-mode-map (general-def 'normal dired-mode-map
"q" 'kill-this-buffer)) "q" 'kill-this-buffer
"C-<return>" 'chris/dired-open-xdg))
#+end_src #+end_src
We need a function to copy the full filename to kill-ring We need a function to copy the full filename to kill-ring
@ -1304,12 +1312,12 @@ Let's add our own eshell prompt. and set the password cache to a significantly h
(propertize path 'face `(:inherit org-level-1)))) (propertize path 'face `(:inherit org-level-1))))
(when chris/eshell-status-p (when chris/eshell-status-p
(propertize (or (chris/eshell-status-display) "") 'face font-lock-comment-face)) (propertize (or (chris/eshell-status-display) "") 'face font-lock-comment-face))
(propertize "\n" 'face '(:inherit org-todo :weight ultra-bold)) (propertize "\n" 'face '(:inherit org-todo :weight ultra-bold))
" ")))) " "))))
;;; If the prompt spans over multiple lines, the regexp should match ;;; If the prompt spans over multiple lines, the regexp should match
;;; last line only. ;;; last line only.
(setq-default eshell-prompt-regexp "^ ") (setq-default eshell-prompt-regexp "^ ")
(setq eshell-destroy-buffer-when-process-dies t) (setq eshell-destroy-buffer-when-process-dies t)
(defun chris/pop-eshell () (defun chris/pop-eshell ()

View file

@ -109,3 +109,4 @@ ls /tmp
cat /tmp/bongo-mpv.socket cat /tmp/bongo-mpv.socket
youtube-dl --list-formats youtube-dl --list-formats
youtube-dl --list-formats https://www.youtube.com/watch?v=ry8T67AgbUM youtube-dl --list-formats https://www.youtube.com/watch?v=ry8T67AgbUM
ls

13
init.el
View file

@ -315,13 +315,20 @@ vertically."
(use-package dired (use-package dired
:ensure nil :ensure nil
:straight nil :straight nil
:config
(defun chris/dired-open-xdg ()
"Open the file-at-point in the appropriate program"
(interactive)
(let ((file (ignore-errors (dired-get-file-for-visit))))
(browse-url (file-truename file))))
:general :general
(chris/leader-keys (chris/leader-keys
:states 'normal :states 'normal
:keymaps 'override :keymaps 'override
"od" '(dired-jump :which-key "open dired here")) "od" '(dired-jump :which-key "open dired here"))
(general-def 'normal dired-mode-map (general-def 'normal dired-mode-map
"q" 'kill-this-buffer)) "q" 'kill-this-buffer
"C-<return>" 'chris/dired-open-xdg))
(defun chris/dired-yank-filename () (defun chris/dired-yank-filename ()
"Get the full filename from file at point and put into kill-ring" "Get the full filename from file at point and put into kill-ring"
@ -995,12 +1002,12 @@ If on a:
(propertize path 'face `(:inherit org-level-1)))) (propertize path 'face `(:inherit org-level-1))))
(when chris/eshell-status-p (when chris/eshell-status-p
(propertize (or (chris/eshell-status-display) "") 'face font-lock-comment-face)) (propertize (or (chris/eshell-status-display) "") 'face font-lock-comment-face))
(propertize "\n" 'face '(:inherit org-todo :weight ultra-bold)) (propertize "\n" 'face '(:inherit org-todo :weight ultra-bold))
" ")))) " "))))
;;; If the prompt spans over multiple lines, the regexp should match ;;; If the prompt spans over multiple lines, the regexp should match
;;; last line only. ;;; last line only.
(setq-default eshell-prompt-regexp "^ ") (setq-default eshell-prompt-regexp "^ ")
(setq eshell-destroy-buffer-when-process-dies t) (setq eshell-destroy-buffer-when-process-dies t)
(defun chris/pop-eshell () (defun chris/pop-eshell ()