bash shell configuration
1 In general
ANSI/VT100 转义序列可用于各种编程语言
\e
\033
\x1B
这3个命令都是设置颜色和类型的开始命令
2 Example
function git_branch {
branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
if [ "${branch}" != "" ];then
if [ "${branch}" = "(no branch)" ];then
branch="(`git rev-parse --short HEAD`...)"
fi
echo " ($branch)"
fi
}
var='\[\e[48;5;28m\][\!]\[\e[45m\]\u@\h\[\e[m\] \[\e[44m\]\w\[\e[m\] \\
\[\e[01;32m\]$(git_branch)\[\033[00m\] \[\e[01;32m\]\$ \[\033[00m\]'
export PS1=$var
The picture as follow:

3 Illustration
| code | description |
|---|---|
| \e[48;5;28m | background color (resolution256) is green, foreground color is white(default) |
| ]!] | history command line number |
| \e[45m | background color is pink |
| \u | username |
| \h | host machine name |
| \e[44m | background color is blue |
| \w | absolute path |
| \e[m | as a end used to end up the front color setting |
| [] | it is important to use to avoid PS1 is covered by command line, and correctly calculate autowrap |
| \e[01;32m | foreground text bold and color green |
| $ | root user is #, and other normal user is $ | |
| \e[00m | used to restore the default setting |
| \ | used to change new line |
4 Reference web link
bash color setting reference: https://blog.csdn.net/u010632165/article/details/92811856

浙公网安备 33010602011771号