Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@leathekd

I got tired of switching to a buffer, doing some work, then having to cd my eshell into the same dir to run some command so I put together the following function.

The function's doc-string describes the change.

@technomancy technomancy merged commit ac6e5df into from
@technomancy
Owner

Slick as snot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2012
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 0 deletions.
  1. +28 −0 modules/starter-kit-eshell.el
View
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
;; http://blog.peepcode.com/tutorials/2009/shell-method-missing/shell_method_missing.rb
;; * cloning git repos, github repos
Something went wrong with that request. Please try again.