Skip to content

Instantly share code, notes, and snippets.

@howardabrams
Last active December 10, 2016 11:36
Show Gist options
  • Save howardabrams/9245265 to your computer and use it in GitHub Desktop.
Save howardabrams/9245265 to your computer and use it in GitHub Desktop.
A function for creating small, temporary eshell buffers that will be "somewhat associated" with a particular buffer (since it is named after the directory that file is in).
(defun eshell-here ()
"Opens up a new shell in the directory associated with the current buffer's file."
(interactive)
(let* ((parent (if (buffer-file-name)
(file-name-directory (buffer-file-name))
default-directory))
(height (/ (window-total-height) 3))
(name (car (last (split-string parent "/" t)))))
(split-window-vertically (- height))
(other-window 1)
(eshell "new")
(rename-buffer (concat "*eshell: " name "*"))
(insert (concat "ls"))
(eshell-send-input)))
(global-set-key (kbd "C-!") 'eshell-here)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment