Skip to content

Instantly share code, notes, and snippets.

@jgarvin
Created November 4, 2015 18:49
Show Gist options
  • Save jgarvin/0627ed76a773ade222f6 to your computer and use it in GitHub Desktop.
Save jgarvin/0627ed76a773ade222f6 to your computer and use it in GitHub Desktop.
eshell f/b
(defvar-local eshell-hist-dirs nil)
(defvar-local eshell-hist-index 0)
(defun etc-eshell-update-hist-dir ()
;; prevent "cd /tmp" over and over from making new entries
(when (not (equal (car (last eshell-hist-dirs)) (eshell/pwd)))
(push (eshell/pwd) eshell-hist-dirs)))
(add-hook 'eshell-directory-change-hook #'etc-eshell-update-hist-dir)
(defun eshell-forward (n)
(unless eshell-hist-dirs
(user-error "eshell-hist-dirs is empty, cd a few times"))
(let ((dirs eshell-hist-dirs))
(prog1 (eshell/cd (nth (setq eshell-hist-index
;; ensure we don't go outside list bounds
(if (> n 0)
(min (- (length eshell-hist-dirs) 1) (+ eshell-hist-index n))
(max 0 (+ eshell-hist-index n))))
dirs))
(setq eshell-hist-dirs dirs))))
(defun eshell/b ()
(eshell-forward 1))
(defun eshell/f ()
(eshell-forward -1))
(defun etc-eshell-mode-hook ()
;; make sure starting directory is in history
(push (eshell/pwd) eshell-hist-dirs))
(add-hook 'eshell-mode-hook #'etc-eshell-mode-hook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment