My Emacs version is:
GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
I have modified my eshell prompt as follows:
(defun set-eshell-prompt-function ()
(setq eshell-prompt-function
(function
(lambda ()
(concat
(propertize (format-time-string "%H:%M:%S" (current-time))
'face
`(:foreground "#A0A0A0"))
"::"
(propertize (user-login-name)
'face
`(:foreground "#FF9080"))
"@"
(propertize (let ((sys-name (system-name)))
(let ((sys-name-len (length sys-name)))
(if (> sys-name-len 8)
(concat (substring sys-name 0 8) "...")
sys-name)))
'face
`(:foreground "#FF9080"))
"::"
(propertize
(let ((limit 36)
(loc
(if (string= (eshell/pwd) (getenv "HOME"))
"~"
(eshell/pwd))))
(let ((loc-length (length loc)))
(if (> loc-length limit)
(concat "..." (substring loc (- loc-length limit)))
loc)))
'face
`(:foreground "#FF9080"))
"$ "))))
(setq eshell-highlight-prompt t)
(setq eshell-prompt-regexp "^[^#$\n]*[#$] "))
(set-eshell-prompt-function)
However, I would like to also see the last command's exit code in the prompt. I could not find the appropriate procedure to call to get it.
How can I get the last exit code, so that I can put it into the prompt?
Edit
At hint of the comment by Marioba, I have tried the following:
(propertize (concat "[" (number-to-string $?) "]")
'face
`(:foreground "#A0A0A0"))
But unfortunately that does not work and results in the following error output in the *Messages*
buffer:
concat: Symbol’s value as variable is void: $\? [2 times]
reference to free variable ‘$\?’
$$
or$?
variables. gnu.org/software/emacs/manual/html_mono/…).init.el
. I edited my post to include the attempt. Thanks nevertheless!