Last active
December 23, 2022 15:01
-
-
Save jordonbiondo/c2926d178d1a1d322267 to your computer and use it in GitHub Desktop.
Custom eshell prompt
This file contains hidden or 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. Neat idea to track last command count.
You might also be interested in some improvements from https://emacs.stackexchange.com/a/33408/15023.