Created
December 13, 2017 19:51
-
-
Save dwcoates/f859787d30b6f69702a2d997e3e4e23e to your computer and use it in GitHub Desktop.
Track eshell sessions dwim-style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar eshell-previous-buffer nil) | |
(defvar eshell-session-alist nil) | |
(defun dwc-switch-to-terminal (arg) | |
(interactive "p") | |
(if (eq arg 4) | |
(progn | |
(let ((sesh (alist-get (current-buffer) eshell-session-alist))) | |
(if sesh | |
(progn | |
(setq eshell-previous-buffer (current-buffer)) | |
(eshell sesh)) | |
(let ((len (length eshell-session-alist))) | |
(push (cons (current-buffer) len) eshell-session-alist) | |
(eshell len))))) | |
(if (string-match-p (regexp-quote eshell-buffer-name) | |
(buffer-name (current-buffer))) | |
(if eshell-previous-buffer | |
(switch-to-buffer eshell-previous-buffer) | |
(previous-buffer)) | |
(setq eshell-previous-buffer (current-buffer)) | |
(eshell)))) | |
(define-key global-map (kbd "C-x j") 'dwc-switch-to-terminal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment