Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add esk-eshell-in-dir to cd an eshell to the dir of the current buffer

  • Loading branch information...
commit c0e568d3c9940c9dd5241e4b49467723590fc2c2 1 parent bc0ee5f
David Leatherman authored
Showing with 28 additions and 0 deletions.
  1. +28 −0 modules/starter-kit-eshell.el
28 modules/starter-kit-eshell.el
@@ -116,6 +116,34 @@
(save-excursion (beginning-of-line) (point)) (point-max)
'(face esk-eshell-error-prompt-face))))))
+(defun esk-eshell-in-dir (&optional prompt)
+ "Change the directory of an existing eshell to the directory of the file in
+ the current buffer or launch a new eshell if one isn't running. If the
+ current buffer does not have a file (e.g., a *scratch* buffer) launch or raise
+ eshell, as appropriate. Given a prefix arg, prompt for the destination
+ directory."
+ (interactive "P")
+ (let* ((name (buffer-file-name))
+ (dir (cond (prompt (read-directory-name "Directory: " nil nil t))
+ (name (file-name-directory name))
+ (t nil)))
+ (buffers (delq nil (mapcar (lambda (buf)
+ (with-current-buffer buf
+ (when (eq 'eshell-mode major-mode)
+ (buffer-name))))
+ (buffer-list))))
+ (buffer (cond ((eq 1 (length buffers)) (first buffers))
+ ((< 1 (length buffers)) (ido-completing-read
+ "Eshell buffer: " buffers nil t
+ nil nil (first buffers)))
+ (t (eshell)))))
+ (with-current-buffer buffer
+ (when dir
+ (eshell/cd (list dir))
+ (eshell-send-input))
+ (end-of-buffer)
+ (pop-to-buffer buffer))))
;; Port features from
;; * cloning git repos, github repos
Please sign in to comment.
Something went wrong with that request. Please try again.