我可以将bash提示的输入颜色更改为不同于终端默认设置的颜色吗? [英] Can I change the input color of my bash prompt to something different than the terminal default
问题描述
我的默认终端颜色是灰色,就可以了.
My default terminal color is gray, that's fine.
我的bash提示符显示一堆颜色,这很好用:
My bash prompt displays a bunch of colors, this works fine:
PS1="${COLOR_RED}\u${COLOR_WHITE}@${COLOR_RED}${COMPUTERNAME} ${COLOR_BLUE}\w${GITPROMPT} ${COLOR_RESET}"
请参见示例: http://cl.ly/image/002f210X1f1u
但是,在提示的结尾处,我键入的文本为灰色.我希望它是白色的(ANSI代码"[37m").
But the text I type in, at the end of the prompt, is gray. I want it to be white (ANSI code "[37m").
如果在提示的末尾添加COLOR_WHITE而不是COLOR_RESET,则默认端子颜色将变为白色,直到将其重置为止.这会产生一些灰色文字的怪异效果,而某些白色文字在顶部穿过.
If I add a COLOR_WHITE at the end of the prompt, instead of the COLOR_RESET, then the default terminal color changes to white until it is reset. This makes a weird effect of some gray text, with some white text bleeding through at the top.
请参阅问题示例: http://cl.ly/image/1Z3g3v0e083B
如何将Bash提示的输入文本"颜色更改为终端默认颜色以外的颜色?感谢您的任何建议!
How can I change the "input text" color of the Bash prompt, to something other than the terminal default color? Thanks for any suggestions!
推荐答案
简单添加以下行:
export PS1=" \[\033[34m\]\u@\h \[\033[33m\]\w\[\033[31m\]\[\033[00m\] $ "
预览:
这是我的首选颜色.您可以通过更改m
代码(例如34m
)(它们是ANSI颜色代码)来自定义提示颜色的每个部分.
This is my preferred colors. You can customize each part of prompt's color by changing m
codes (e.g. 34m
) which are ANSI color codes.
ANSI颜色代码列表:
- 黑色:30m
- 红色:31m
- 绿色:32m
- 黄色:33m
- 蓝色:34m
- 紫色:35m
- 青色:36m
- 白色:37m
这篇关于我可以将bash提示的输入颜色更改为不同于终端默认设置的颜色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!