您的位置:首页 > 运维架构 > Shell

控制shell终端提示符格式和颜色

2013-09-15 21:06 316 查看
字体颜色值

(ASCII)

背景颜色值

(ASCII)

显示颜色
3040黑色
3141红色
3242绿色
3343黄色
3444蓝色
3545紫红色
3646青蓝色
3747白色
符 号值特效取反
0OFF
1HighLight
2半亮22
4UndeLine24
5Blink25
7反白27
8不可见
注:若着色不对,哈哈,请认为我是色盲吧。

特殊字符着色规则:

着色开始    着色结束

 \[\e[[b]*[/b]m\]     \e[0m

若使用背景颜色或特效需要用[b][b];[/b]分割成[b]*;*[/b][/b]格式 ,"*"代表表中数值(其值见上两表)

如:(方式一 非永久性)

  



# .bashrc

export PS1="你的设置"

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions


特殊字符语法规则:

\a     an ASCII bell character (07)
\d     the date in "Weekday Month Date" format (e.g.,  "Tue  May
26")
\D{format}
the  format  is  passed  to strftime(3) and the result is
inserted into the prompt string; an empty format  results
in a locale-specific time representation.  The braces are
required
\e     an ASCII escape character (033)
\h     the hostname up to the first ‘.’
\H     the hostname
\j     the number of jobs currently managed by the shell
\l     the basename of the shell’s terminal device name
\n     newline
\r     carriage return
\s     the name of the shell, the basename of  $0  (the  portion
following the final slash)
\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format
\u     the username of the current user
\v     the version of bash (e.g., 2.00)
\V     the release of bash, version + patch level (e.g., 2.00.0)
\w     the current working  directory,  with  $HOME  abbreviated
with  a tilde (uses the value of the PROMPT_DIRTRIM vari-
able)
\W     the basename of the current working directory, with $HOME
abbreviated with a tilde
\!     the history number of this command
\#     the command number of this command
\$     if the effective UID is 0, a #, otherwise a $
\nnn   the character corresponding to the octal number nnn
\\     a backslash
\[     begin  a sequence of non-printing characters, which could
be used to embed a terminal  control  sequence  into  the
prompt
\]     end a sequence of non-printing characters


这是我的 (方式二)

编辑.bashrc文件

$ vim ~/.bashrc


在该文件的
# User specific aliases and functions

下面添加如下内容

c1="\[\e[36m\]"
c2="\e[0m"
c3="\[\e[35m\]"
c4="\[\e[32m\]"
c5="\[\e[30m\]"
c6="\[\e[31m\]"
c7="\[\e[34m\]"

export PS1="$c1[$c2$c5\t$c2$c6@$c2$c3\u$c2 $c4\w$c2$c5]$c2$c7\$$c2 "


为什么选 \w 呢?因为 cd 很方便嘛......
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: