Skip to content

Instantly share code, notes, and snippets.

@jordonbiondo
Last active December 23, 2022 15:01
Show Gist options
  • Select an option

  • Save jordonbiondo/c2926d178d1a1d322267 to your computer and use it in GitHub Desktop.

Select an option

Save jordonbiondo/c2926d178d1a1d322267 to your computer and use it in GitHub Desktop.
Custom eshell prompt
(defvar my-eshell-command-count 0
"Variable to keep track of command count")
;; very important if you have multiple eshell buffers open
(make-variable-buffer-local 'my-eshell-command-count)
(defun my-increment-eshell-command-count ()
"Increments the eshell command count var."
(incf my-eshell-command-count))
(defun color-me (text color &optional bg-color)
"Color TEXT with a foreground of COLOR and background of BG-COLOR if given."
(propertize text 'face (list :foreground color :background bg-color)))
(defun my-eshell-prompt ()
"Custom eshell prompt function."
(concat
(color-me (abbreviate-file-name (eshell/pwd)) "skyblue")
" "
(color-me "[" "gray70")
(color-me (int-to-string my-eshell-command-count) "orange")
(color-me ":" "gray70")
(color-me (int-to-string (if (numberp eshell-last-command-status) eshell-last-command-status 0))
(if (zerop eshell-last-command-status) "olivedrab" "firebrick"))
(color-me "]" "gray70")
" "
(color-me "->" "magenta")
"\n "
(color-me "$" "purple")
" "))
(defun my-eshell-setup ()
;; this shell colors itself, no need to highlight
(setq eshell-highlight-prompt nil)
;; use the custom prompt
(setq eshell-prompt-function 'my-eshell-prompt)
;; make sure we increment the custom count var after each prompt
(add-hook 'eshell-after-prompt-hook 'my-increment-eshell-command-count))
(my-eshell-setup)
(add-hook 'eshell-mode-hook 'my-eshell-setup)
@mrcnski
Copy link

mrcnski commented Dec 23, 2022

Thanks. Neat idea to track last command count.

You might also be interested in some improvements from https://emacs.stackexchange.com/a/33408/15023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment