From bec6fdbc3ff96e74b154bdbfd5be8fe2aec1d2f8 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 16 Oct 2024 16:30:13 +0100 Subject: Extend +eshell/goto to allow finding files Instead of only looking at directories, +eshell/goto now works with files. If a directory is selected, set eshell to that directory. If a file is selected, make eshell go to the directory where that file is contained then use find-file. --- Emacs/.config/emacs/elisp/eshell-additions.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Emacs/.config/emacs/elisp/eshell-additions.el b/Emacs/.config/emacs/elisp/eshell-additions.el index b18a8e8..51cdf21 100644 --- a/Emacs/.config/emacs/elisp/eshell-additions.el +++ b/Emacs/.config/emacs/elisp/eshell-additions.el @@ -30,7 +30,11 @@ ;; Aliases (defun eshell/goto (&rest args) "Use `read-directory-name' to change directories" - (eshell/cd (list (read-directory-name "Directory?: ")))) + (let* ((name (read-file-name "Choose file: ")) + (dir (file-name-directory name))) + (eshell/cd (list dir)) + (if (not (file-directory-p name)) + (find-file name)))) (defun eshell/project-root (&rest args) "Change to directory `project-root'" -- cgit v1.2.3-13-gbd6f