2014-09-13 114 views
7

是否可以使用bash PS1变量在Emacs shell提示符(提示本身,而不是shell屏幕的其余部分)中使用颜色?我相信我的语法是正确的(例如,PS1='[\[email protected]\h \[\e[0;31m\]\W\[\e[m\]]\$ ' - 它可以在term或ansi-term中运行),但Emacs似乎正在应用comint-highlight-prompt face。我可以将其设置为某种颜色,并且它可以工作,但我希望能够将提示的各个部分设置为不同的颜色。我更喜欢使用shell或term-term,所以我宁愿不切换。Emacs shell提示中的颜色

谢谢。

回答

6

想通了:该comint-highlight-prompt脸被设定为minibuffer-prompt继承,这是设置:weight:foreground:background。删除继承可以防止在PS1中设置的颜色被comint-highlight-prompt表面覆盖。将此添加到我的.emacs文件中。

(set-face-attribute 'comint-highlight-prompt nil 
        :inherit nil) 

此外,M-x customize-group <ret> font-lock-faces有助于解决这一问题。

+0

由于Emacs bug https://debbugs.gnu.org/cgi/bugreport.cgi?bug=20084已在git://git.sv.gnu上修复,因此在Ubuntu 16.04中无法使用Emacs 24.5 .org/emacs.git在提交792d44b3c31d2a682607ab8b79ae7d26b7402f41。要使您的解决方案有效,请使用https://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks-for-Loading.html和“comint”修复“comint-snapshot-last-prompt”和“comint-output-filter”和“font-lock”添加“font-lock-remove-face-from-text-property”。 – 2016-12-27 17:07:59

0

我用它来改变终端的颜色和MAC信息,也许可以帮助:

Cyan="$(tput setaf 6)" 
NC="$(tput sgr0)" # No Color 
export PS1="$Cyan.Where-> \w\n\\$\[$NC\]" 
+0

谢谢,但它仍然被设置为comint-highlight-prompt face。我曾尝试在我的.emacs文件中执行'(set-face-foreground'comint-highlight-prompt nil)',但提示符仍被设置为全部青色。 – 2014-09-13 01:58:16

-1

你需要使用ANSI长期的,而不是外壳为终端的颜色。

+1

好吧,我在shell中有终端颜色,我只是无法控制它们的提示与PS1(或其他方法)。 – 2014-09-13 14:44:06