From 897ab273a0dd6808271ac8e327bc60c3f5a9c22c Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 26 Oct 2020 13:36:09 -0700 Subject: [PATCH] =?UTF-8?q?Add=20command=20to=20switch=20to=20a=20buffer?= =?UTF-8?q?=E2=80=99s=20directory=20in=20eshell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oni-eshell.el | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/oni-eshell.el b/oni-eshell.el index 6bcadf6..7f8e9ed 100644 --- a/oni-eshell.el +++ b/oni-eshell.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2020.0908.002925 +;; Version: 2020.1026.133507 ;; Package-Requires: (eshell-fringe-status esh-autosuggest xterm-color eshell-syntax-highlighting) ;; This program is free software; you can redistribute it and/or modify @@ -28,6 +28,7 @@ (require 'eshell) +(require 'em-dirs) (require 'em-prompt) (require 'esh-autosuggest) (require 'xterm-color) @@ -67,6 +68,18 @@ "Set ‘company-posframe-active-map’ to ‘esh-autosuggest-active-map’." (setq-local company-posframe-active-map esh-autosuggest-active-map)) +(defun oni-eshell-goto-buffer-directory (buffer-name) + "Change the current directory to the given BUFFER-NAME’s directory." + (interactive + (list (read-buffer "Switch to buffer’s directory: " + nil t (lambda (buf) + (let ((b (if (consp buf) + (cdr buf) + (get-buffer buf)))) + (buffer-file-name b)))))) + (eshell/cd (file-name-directory (buffer-file-name (get-buffer buffer-name)))) + (eshell-reset)) + (add-hook 'eshell-before-prompt-hook #'oni-eshell--set-xterm-variables) (add-hook 'eshell-first-time-mode-hook #'oni-eshell--set-eshell-C-d) (add-hook 'eshell-load-hook #'oni-eshell--disable-ansi-color-handling) @@ -78,6 +91,8 @@ (add-hook 'esh-autosuggest-mode-hook #'oni-eshell-fix-esh-autosuggest-active-keymap) +(define-key eshell-mode-map (kbd "C-c b") #'oni-eshell-goto-buffer-directory) + (when (display-graphic-p) (add-hook 'eshell-mode-hook 'eshell-fringe-status-mode))