Emacs中的颜色提示符 [英] Colors in Emacs shell prompt
问题描述
是否可以使用bash PS1变量在Emacs shell提示符(提示本身,而不是其他shell屏幕)中使用颜色?我相信我的语法正确(例如, PS1 ='[\u @ \h \ [\e [0; 31m\] \W\ [\e m\]] \ $'
- 它可以在术语或ansi-term中工作),但是似乎Emacs正在应用comint-highlight-prompt面。我可以将其设置为某种颜色,它可以工作,但是我想要将提示的各个部分设置为不同的颜色。我更喜欢使用shell over term或ansi-term,所以我宁愿不要切换。
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.
谢谢。
推荐答案
取出来: comint-highlight-prompt
face被设置为继承自 minibuffer-prompt
,设置:weight
,:foreground
和背景
。删除继承阻止了 PS1
中设置的颜色被 comint-highlight-prompt
面覆盖。添加到我的 .emacs
文件。
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)
另外, Mx自定义组< ret> font-lock-faces
有助于弄清楚这一点。
Also, M-x customize-group <ret> font-lock-faces
was helpful in figuring this out.
这篇关于Emacs中的颜色提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!