控制shell终端提示符格式和颜色
2013-09-15 21:06
316 查看
字体颜色值 (ASCII) | 背景颜色值 (ASCII) | 显示颜色 |
30 | 40 | 黑色 |
31 | 41 | 红色 |
32 | 42 | 绿色 |
33 | 43 | 黄色 |
34 | 44 | 蓝色 |
35 | 45 | 紫红色 |
36 | 46 | 青蓝色 |
37 | 47 | 白色 |
符 号值 | 特效 | 取反 |
0 | OFF | |
1 | HighLight | |
2 | 半亮 | 22 |
4 | UndeLine | 24 |
5 | Blink | 25 |
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 很方便嘛......
相关文章推荐
- shell脚本编程(严格的终端格式控制,美丽的输出字体颜色)
- shell脚本编程(严格的终端格式控制,美丽的输出字体颜色)
- shell脚本(严格的终端格式控制,美丽的输出字体颜色)
- 自定义shell终端提示符及颜色即修改 PS1文件 (以Centos为例)
- shell终端中更改提示符颜色
- shell脚本函数:控制颜色、定位、居中显示的代码
- 控制输出颜色的shell脚本
- Linux终端执行shell脚本,提示权限不够的解决办法
- ubuntu 友好终端 字体颜色 shell终端颜色 修改
- shell脚本函数:控制颜色、定位、居中显示的代码
- 修改shell终端提示信息
- 终端字符颜色、样式控制
- 修改shell终端提示信息
- Linux终端输出颜色控制
- python xlwt写excel格式控制 颜色、模式、编码、背景色
- 让Shell终端下的svn diff支持颜色高亮
- 如何在Linux终端里用Shell和C输出带颜色的文字
- shell 终端字符颜色
- SHELL输出颜色和闪烁控制
- 修改shell终端提示信息