commit 829347cef2ee0e0aa9cde400a56ecfedfa104126 parent 9f38d5750ee8b50091882749ce93c551ec4211c3 Author: Vincent Demeester <vincent@sbr.pm> Date: Wed, 13 Oct 2021 16:23:49 +0200 tools/emacs: add eshell/j to jump folders in eshell Signed-off-by: Vincent Demeester <vincent@sbr.pm> Diffstat:
M | tools/emacs/config/config-shells.el | | | 21 | +++++++++++++++++++++ |
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/tools/emacs/config/config-shells.el b/tools/emacs/config/config-shells.el @@ -73,6 +73,27 @@ The EShell is renamed to match that directory to make multiple windows easier." (error "Don't know how to extract %s" file))) file))) + ;; From https://karthinks.com/software/jumping-directories-in-eshell/ + (defun eshell/j (&optional regexp) + "Navigate to a previously visited directory in eshell, or to +any directory proferred by `consult-dir'." + (let ((eshell-dirs (delete-dups + (mapcar 'abbreviate-file-name + (ring-elements eshell-last-dir-ring))))) + (cond + ((and (not regexp) (featurep 'consult-dir)) + (let* ((consult-dir--source-eshell `(:name "Eshell" + :narrow ?e + :category file + :face consult-file + :items ,eshell-dirs)) + (consult-dir-sources (cons consult-dir--source-eshell + consult-dir-sources))) + (eshell/cd (substring-no-properties + (consult-dir--pick "Switch directory: "))))) + (t (eshell/cd (if regexp (eshell-find-previous-directory regexp) + (completing-read "cd: " eshell-dirs))))))) + (add-hook 'eshell-mode-hook (lambda ()