2014-09-13 32 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