diff options
author | Franck Cuny <franck@fcuny.net> | 2021-10-27 08:30:10 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2021-10-27 08:30:10 -0700 |
commit | 9797b773f6cd8798b8d467c9ccd92e0a44af32f0 (patch) | |
tree | 755a3b0f14c28e483dbe762219abda19c42e46e9 /emacs | |
parent | emacs: use powerline (diff) | |
download | emacs.d-9797b773f6cd8798b8d467c9ccd92e0a44af32f0.tar.gz |
eshell: open file at point
Add a function to open the file at point. In an eshell session, I can then move the cursor to a file or a directory, and call `fcuny/eshell-open-file-at-point`: for a file, a new buffer is open, if it's a directory, we're changing the working directory to the given path. Bind the function to "C-o" in eshell.
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/custom/fcuny-eshell.el | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/emacs/custom/fcuny-eshell.el b/emacs/custom/fcuny-eshell.el index 53c3f69..2f53988 100644 --- a/emacs/custom/fcuny-eshell.el +++ b/emacs/custom/fcuny-eshell.el @@ -51,6 +51,25 @@ (magit-status (pop args) nil) (eshell/echo)) ;; The echo command suppresses output +(defun fcuny/eshell--open-or-cd (path) + "Cd to PATH if path is a directory ((file-name-directory path) => t), otherwise open PATH via `find-file'." + (interactive) + (if (file-directory-p path) + (progn + (goto-char (point-max)) + (insert (concat "cd " path)) + (eshell-send-input)) + (find-file path))) + +(defun fcuny/eshell-open-file-at-point () + (interactive) + (let ((filename (symbol-name (symbol-at-point)))) + (cond + ((file-readable-p filename) + (fcuny/eshell--open-or-cd filename)) + ((file-readable-p (expand-file-name filename)) + (fcuny/eshell--open-or-cd (expand-file-name filename)))))) + (defun fcuny/shorten-path (path &optional max-len) "Return a potentially trimmed-down version of the directory PATH, replacing parent directories with their initial characters to try to get the character @@ -168,7 +187,9 @@ append to it, while separating multiple outputs with :commands (eshell eshell-command) :bind (("C-c e h" . fcuny/eshell-here) ("C-c e e" . fcuny/eshell-export) - ("C-c r" . counsel-esh-history)) + ("C-c r" . counsel-esh-history) + :map eshell-mode-map + ("C-o" . fcuny/eshell-open-file-at-point)) :custom (eshell-scroll-to-bottom-on-input 'all) (eshell-error-if-no-glob t) |