zsh change prompt input color

一世执手 提交于 2019-12-04 22:31:35

问题


I want to change the color of the input text in zsh (the text that I type for each command). Example: in user@host> ls ~/ I would want ls ~/ to be yellow to stand out from standard output.

I know I can accomplish this in bash using

export PS1=" $BIGreen \u@\h \w \$ $IYellow" 

At the end of the prompt, the color is set to Yellow, input text I type is yellow (with the appropriate color variables defined). And then

trap 'echo -ne "\e[0m"' DEBUG

Which resets the color to normal when the outputs of my command are displayed.

How can I accomplish this in zsh? Currently, I have

PROMPT=$'{$fg[green]%}%n@%{$fg[green]%}%m %# %{$fg[yellow]%}'

in .zshrc (setting color to yellow at the end) but it does not work. (I also wouldn't know how to set the color back to white after the command).


回答1:


Try this:

PROMPT="%F{green}%n@%m %# %F{yellow}"
preexec () { echo -ne "\e[0m" }

I tried using trap, but it looks like DEBUG doesn't happen until after the command runs/before the next prompt, so the command ends up executing in yellow. The preexec() function gets called before the command executes, so you can restore the default color there.



来源:https://stackoverflow.com/questions/9268836/zsh-change-prompt-input-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!