[Emacs] Replace dired with dirvish, optimize TRAMP
This commit is contained in:
parent
489074ddf1
commit
c6a3771ff4
@ -3149,50 +3149,110 @@ any graphical file manager for me most of the time because:
|
|||||||
- All actions can be done with keybindings
|
- All actions can be done with keybindings
|
||||||
- I get a consistent behavior between Dired and Emacs, since it’s the
|
- I get a consistent behavior between Dired and Emacs, since it’s the
|
||||||
same thing.
|
same thing.
|
||||||
However, the only thing I lack still is thumbnails. In any case, I
|
I used to have an extensive configuration for Dired with a couple of
|
||||||
need still to make some tweaks in order to make it usable for
|
additional packages to make it more usable. Dirvish rendered that
|
||||||
me.
|
obsolete!
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(use-package dired
|
(use-package dirvish
|
||||||
:straight (:type built-in)
|
:straight (:build t)
|
||||||
:defer t
|
:defer t
|
||||||
:hook (dired-mode . turn-on-gnus-dired-mode)
|
:init (dirvish-override-dired-mode)
|
||||||
|
:custom
|
||||||
|
(dirvish-quick-access-entries
|
||||||
|
'(("h" "~/" "Home")
|
||||||
|
("d" "~/Downloads/" "Downloads")
|
||||||
|
("c" "~/org/config" "Config")
|
||||||
|
("C" "~/Documents/conlanging/content" "Conlanging")))
|
||||||
|
(dirvish-mode-line-format
|
||||||
|
'(:left (sort file-time "" file-size symlink) :right (omit yank index)))
|
||||||
|
(dirvish-attributes '(all-the-icons file-size collapse subtree-state vc-state git-msg))
|
||||||
|
:config
|
||||||
|
(dirvish-peek-mode)
|
||||||
|
<<dired-drag-and-drop>>
|
||||||
|
<<dired-listing-flags>>
|
||||||
|
<<dired-files-and-dirs>>
|
||||||
|
<<dirvish-exa-offload>>
|
||||||
|
(csetq dired-dwim-target t
|
||||||
|
dired-recursive-copies 'always
|
||||||
|
dired-recursive-deletes 'top
|
||||||
|
delete-by-moving-to-trash t)
|
||||||
:general
|
:general
|
||||||
(phundrak/evil
|
(phundrak/evil
|
||||||
:keymaps 'dired-mode-map
|
:keymaps 'dirvish-mode-map
|
||||||
:packages 'dired
|
:packages '(dired dirvish)
|
||||||
"(" #'dired-hide-details-mode
|
"q" #'dirvish-quit
|
||||||
"n" #'evil-next-line
|
"TAB" #'dirvish-subtree-toggle)
|
||||||
"p" #'evil-previous-line)
|
(phundrak/major-leader-key
|
||||||
:config
|
:keymaps 'dirvish-mode-map
|
||||||
(csetq dired-dwim-target t
|
:packages '(dired dirvish)
|
||||||
dired-recursive-copies 'always
|
"a" #'dirvish-quick-access
|
||||||
dired-recursive-deletes 'top
|
"e" #'dirvish-emerge-menu
|
||||||
dired-listing-switches "-ahl1v --time-style=long-iso --group-directories-first"
|
"f" #'dirvish-fd-jump
|
||||||
dired-auto-revert-buffer t
|
"F" #'dirvish-file-info-menu
|
||||||
image-dired-thumb-size 150
|
"h" '(:ignore t :which-key "history")
|
||||||
image-dired-dir (expand-file-name (file-name-as-directory "dired-img")
|
"hp" #'dirvish-history-go-backward
|
||||||
user-emacs-directory)
|
"hn" #'dirvish-history-go-forward
|
||||||
image-dired-db-file (expand-file-name "dired-db.el" user-emacs-directory)
|
"hj" #'dirvish-history-jump
|
||||||
image-dired-gallery-dir (expand-file-name (file-name-as-directory "gallery")
|
"hl" #'dirvish-history-last
|
||||||
user-emacs-directory)
|
"l" '(:ignore t :which-key "layout")
|
||||||
image-dired-temp-image-file (expand-file-name "temp-image" image-dired-dir)
|
"ls" #'dirvish-layout-switch
|
||||||
image-dired-temp-rotate-image-file (expand-file-name "temp-rotate-image"
|
"lt" #'dirvish-layout-toggle
|
||||||
image-dired-dir)))
|
"m" #'dirvish-mark-menu
|
||||||
|
"s" #'dirvish-quicksort
|
||||||
|
"S" #'dirvish-setup-menu
|
||||||
|
"y" #'dirvish-yank-menu
|
||||||
|
"n" #'dirvish-narrow))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Dired-x stands for “dired extra” which provides a couple more features
|
Since Emacs 29, it is possible to enable drag-and-drop between Emacs
|
||||||
that are for some reason not included in dired yet.
|
and other applications.
|
||||||
#+begin_src emacs-lisp
|
#+name: dired-drag-and-drop
|
||||||
(use-package dired-x
|
#+begin_src emacs-lisp :tangle no
|
||||||
:straight (:type built-in)
|
(csetq dired-mouse-drag-files t
|
||||||
:after dired
|
mouse-drag-and-drop-region-cross-program t)
|
||||||
:commands (dired-jump dired-jump-other-window dired-omit-mode)
|
#+end_src
|
||||||
:general
|
|
||||||
(phundrak/evil
|
In Dirvish, it’s best to use the long name of flags whenever possible,
|
||||||
:keymaps 'dired-mode-map
|
otherwise some commands won’t work.
|
||||||
:packages 'dired-x
|
#+name: dired-listing-flags
|
||||||
"«" #'dired-omit-mode))
|
#+begin_src emacs-lisp :tangle no
|
||||||
|
(csetq dired-listing-switches (string-join '("--all"
|
||||||
|
"--human-readable"
|
||||||
|
"--time-style=long-iso"
|
||||||
|
"--group-directories-first"
|
||||||
|
"-lv1")
|
||||||
|
" "))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
However, it is possible to instead use ~exa~ when it is available.
|
||||||
|
Instead of making Emacs’ main thread to the file listing in a
|
||||||
|
directory, we offload it to an external thread.
|
||||||
|
#+name: dirvish-exa-offload
|
||||||
|
#+begin_src emacs-lisp :tangle no
|
||||||
|
(dirvish-define-preview exa (file)
|
||||||
|
"Use `exa' to generate directory preview."
|
||||||
|
:require ("exa")
|
||||||
|
(when (file-directory-p file)
|
||||||
|
`(shell . ("exa" "--color=always" "-al" ,file))))
|
||||||
|
|
||||||
|
(add-to-list 'dirvish-preview-dispatchers 'exa)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Finally, some directories need to be set for Dired to store various
|
||||||
|
files and images.
|
||||||
|
#+name: dired-files-and-dirs
|
||||||
|
#+begin_src emacs-lisp :tangle no
|
||||||
|
(let ((my/file (lambda (path &optional dir)
|
||||||
|
(expand-file-name path (or dir user-emacs-directory))))
|
||||||
|
(my/dir (lambda (path &optional dir)
|
||||||
|
(expand-file-name (file-name-as-directory path)
|
||||||
|
(or dir user-emacs-directory)))))
|
||||||
|
(csetq image-dired-thumb-size 150
|
||||||
|
image-dired-dir (funcall my/dir "dired-img")
|
||||||
|
image-dired-db-file (funcall my/file "dired-db.el")
|
||||||
|
image-dired-gallery-dir (funcall my/dir "gallery")
|
||||||
|
image-dired-temp-image-file (funcall my/file "temp-image" image-dired-dir)
|
||||||
|
image-dired-temp-rotate-image-file (funcall my/file "temp-rotate-image" image-dired-dir)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Copying files with Dired is a blocking process. It’s usually fine when
|
Copying files with Dired is a blocking process. It’s usually fine when
|
||||||
@ -3212,84 +3272,6 @@ happening.
|
|||||||
"C-r" #'dired-rsync))
|
"C-r" #'dired-rsync))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
~dired-du~ provides the user with the option to be able to see the size
|
|
||||||
of directories as they are, rather than just the size of their
|
|
||||||
inode. However, I will not enable it by default as it can take some
|
|
||||||
time to get the actual size of a directory.
|
|
||||||
#+begin_src emacs-lisp
|
|
||||||
(use-package dired-du
|
|
||||||
:after dired
|
|
||||||
:straight (:build t)
|
|
||||||
:general
|
|
||||||
(phundrak/evil
|
|
||||||
:keymaps 'dired-mode-map
|
|
||||||
:packages 'dired-du
|
|
||||||
"»" #'dired-du-mode))
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
This package on the other hand provides Git information to the user in
|
|
||||||
the current dired buffer in a similar way to how Github and Gitea
|
|
||||||
display the latest commit message and its age about a file in the file
|
|
||||||
tree. And by default, I want ~dired-git-info~ to hide file details.
|
|
||||||
#+begin_src emacs-lisp
|
|
||||||
(use-package dired-git-info
|
|
||||||
:after (dired)
|
|
||||||
:straight (:build t)
|
|
||||||
:hook (dired-after-reading . dired-git-info-auto-enable)
|
|
||||||
:general
|
|
||||||
(phundrak/evil
|
|
||||||
:keymaps 'dired-mode-map
|
|
||||||
:packages 'dired-git-info
|
|
||||||
")" #'dired-git-info-mode)
|
|
||||||
:config
|
|
||||||
(setq dgi-auto-hide-details-p t))
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Diredfl makes dired colorful, and much more readable in my opinion.
|
|
||||||
#+begin_src emacs-lisp
|
|
||||||
(use-package diredfl
|
|
||||||
:after (dired all-the-icons)
|
|
||||||
:straight (:build t)
|
|
||||||
:init
|
|
||||||
(diredfl-global-mode 1))
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Dired can benefit from ~fd~, a fast reimplementation of ~find~, to
|
|
||||||
increase the speed of ~find-dired~.
|
|
||||||
#+begin_src emacs-lisp
|
|
||||||
(use-package fd-dired
|
|
||||||
:if (executable-find "fd")
|
|
||||||
:defer t
|
|
||||||
:straight (:build t)
|
|
||||||
:init
|
|
||||||
(global-set-key [remap find-dired] #'fd-dired))
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
And let’s add some fancy icons in dired!
|
|
||||||
#+begin_src emacs-lisp
|
|
||||||
(use-package all-the-icons-dired
|
|
||||||
:after (all-the-icons)
|
|
||||||
:straight (:build t)
|
|
||||||
:defer t
|
|
||||||
:hook (dired-mode . all-the-icons-dired-mode)
|
|
||||||
:config
|
|
||||||
(defun my/all-the-icons-dired--refresh (orig-fun &rest args)
|
|
||||||
(unless (or (not (file-remote-p default-directory))
|
|
||||||
(<= (count-lines (point-min) (point-max)) 512))
|
|
||||||
(apply orig-fun args)))
|
|
||||||
(advice-add #'all-the-icons-dired--refresh
|
|
||||||
:around
|
|
||||||
#'my/all-the-icons-dired--refresh))
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Lastly, let’s install some extensions to ~image-dired~.
|
|
||||||
#+begin_src emacs-lisp
|
|
||||||
(use-package image-dired+
|
|
||||||
:after (image-dired)
|
|
||||||
:straight (:build t)
|
|
||||||
:init (image-diredx-adjust-mode 1))
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
*** Compilation mode
|
*** Compilation mode
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: Packages-Configuration-Emacs-built-ins-Compilation-mode-7nh817m0t8j0
|
:CUSTOM_ID: Packages-Configuration-Emacs-built-ins-Compilation-mode-7nh817m0t8j0
|
||||||
@ -3624,13 +3606,15 @@ various hosts using various protocols, such as ~ssh~ and
|
|||||||
~rsync~. However, I have some use-case for Tramp which are not
|
~rsync~. However, I have some use-case for Tramp which are not
|
||||||
supported natively. I will describe them here.
|
supported natively. I will describe them here.
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(require 'tramp)
|
|
||||||
(use-package tramp
|
(use-package tramp
|
||||||
:straight (tramp :type built-in :build t)
|
:straight (tramp :type built-in :build t)
|
||||||
:init
|
:init
|
||||||
<<tramp-add-yadm>>
|
<<tramp-add-yadm>>
|
||||||
:config
|
:config
|
||||||
(setq tramp-ssh-controlmaster-options "")
|
(csetq tramp-ssh-controlmaster-options nil
|
||||||
|
tramp-verbose 0
|
||||||
|
tramp-auto-save-directory (locate-user-emacs-file "tramp/")
|
||||||
|
tramp-chunksize 2000)
|
||||||
(add-to-list 'backup-directory-alist ; deactivate auto-save with TRAMP
|
(add-to-list 'backup-directory-alist ; deactivate auto-save with TRAMP
|
||||||
(cons tramp-file-name-regexp nil)))
|
(cons tramp-file-name-regexp nil)))
|
||||||
#+end_src
|
#+end_src
|
||||||
@ -8374,7 +8358,7 @@ My keybinds for jumping around are prefixed by ~j~.
|
|||||||
|-----+-------------------------+-------------|
|
|-----+-------------------------+-------------|
|
||||||
| | | jump |
|
| | | jump |
|
||||||
| f | counsel-file-jump | |
|
| f | counsel-file-jump | |
|
||||||
| d | dired-jump | |
|
| d | dirvish-dwim | |
|
||||||
| D | dired-jump-other-window | |
|
| D | dired-jump-other-window | |
|
||||||
|
|
||||||
** Project
|
** Project
|
||||||
|
Loading…
Reference in New Issue
Block a user