From 6186ed668679bda23db730665be1f298e96f38a2 Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Sun, 15 Sep 2024 23:07:37 -0700 Subject: [PATCH] Add jump function for eshell --- thoom-emacs/modules/thoom-prog.el | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/thoom-emacs/modules/thoom-prog.el b/thoom-emacs/modules/thoom-prog.el index 558632a..71c34ba 100644 --- a/thoom-emacs/modules/thoom-prog.el +++ b/thoom-emacs/modules/thoom-prog.el @@ -48,7 +48,28 @@ (use-package eshell :config - (setq eshell-destroy-buffer-when-process-dies t)) + (setq eshell-destroy-buffer-when-process-dies t) + + ;; 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)))))))) (use-package eshell-toggle :ensure t