Is it possible to use colors in the Emacs shell prompt (the prompt itself, not the rest of the shell screen) with the bash PS1 variable? I believe I have the syntax correct (e.g., PS1='[\u@\h \[\e[0;31m\]\W\[\e[m\]]\$ '
- it works in term or ansi-term), but it seems like Emacs is applying the comint-highlight-prompt face. I can set that to some color, and it works, but I want to be able to set individual parts of the prompt to different colors. I prefer using shell over term or ansi-term, so I'd rather not switch.
Thanks.
Here's what you need to know: You must include the entire color code information between the \[ and \] character s. Inside the tag, you must begin with either \033[ or \e[ to indicate to Bash that this is color information. Both \033[ and \e[ do the same thing.
7.7 How do I use a shell in Emacs? You can start an interactive shell in Emacs by typing M-x shell . By default, this will start the standard Windows shell cmd.exe . Emacs uses the SHELL environment variable to determine which program to use as the shell.
Figured it out: The comint-highlight-prompt
face was set to inherit from minibuffer-prompt
, which was setting the :weight
, :foreground
and :background
. Removing the inheritance prevented the colors set in PS1
from being overridden by the comint-highlight-prompt
face. Added this to my .emacs
file.
(set-face-attribute 'comint-highlight-prompt nil
:inherit nil)
Also, M-x customize-group <ret> font-lock-faces
was helpful in figuring this out.
I would recommend not to change the face globally (since there are many comint users besides shell mode) but in a buffer specific manner by setting a mode hook:
(add-hook 'shell-mode-hook
(lambda ()
(face-remap-set-base 'comint-highlight-prompt :inherit nil)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With