Eshell is an independent command interpreter implemented in Elisp, so by default it should have nothing to do with your other dotfiles, such as ~/.bashrc
.
The custom prompt function you list works for me in the development version of Emacs on GNU/Linux, so I assume the problem lies either between Emacs and Windows or with your user-init-file
.
I am not qualified to debug or explain the former case, but the latter should be relatively straightforward to test. First invoke Emacs with the -Q
option and then evaluate your listed code. See here and here for ways to interactively evaluate Lisp if this is not familiar to you. Whether the custom code is evaluated before or after invoking eshell
should not make a difference in this case (in fact, you could even compare eshell
's appearance before and after evaluating the code).
If the -Q
option resolves your issue, this means it is probably arising from something in your user-init-file
. In this case I recommend you recursively bisect it as per this answer and this answer by Drew. Otherwise I suggest emphasising that this support issue is Windows-specific.
P.S. I suggest an improvement to the custom code, to better align it with the default implementation of eshell
:
(defun my-eshell-prompt ()
"Highlight eshell pwd and prompt separately."
(mapconcat
(lambda (list)
(propertize (car list)
'read-only t
'font-lock-face (cdr list)
'front-sticky '(font-lock-face read-only)
'rear-nonsticky '(font-lock-face read-only)))
`((,(abbreviate-file-name (eshell/pwd)) :foreground "blue")
(,(if (zerop (user-uid)) " # " " $ ") :foreground "green"))
""))
(setq eshell-highlight-prompt nil
eshell-prompt-function #'my-eshell-prompt)
Noteworthy changes:
- Give
eshell-prompt-function
a human-readable name for M-x describe-variable
(C-h v
) to report.
- Make all prompt components
read-only
, so that the prompt cannot be deleted as regular text. Allow text inserted before the prompt to inherit this property, as per eshell
defaults.
- Replace the
face
property with font-lock-face
and do not allow text inserted after the prompt to inherit this property. I must admit I am not entirely familiar with the differences between face
and font-lock-face
, but I suggest this change because:
eshell
does this;
- it should achieve the same effect; and
- the effects of
font-lock-face
can be toggled with font-lock-mode
.
- Choose between prompts
#
and $
depending on user privileges, as per Bourne and eshell
defaults.
- Try to
abbreviate-file-name
of current directory as per eshell
defaults, e.g. display ~
instead of /path/to/user/home
.