PS1="\[\e[36;1m\][\u@\[\e[32;1m\]\H \[\e[31;1m\]\w]# \[\e[0m\]"
PS1="\[[\e[1;32m\]\u\[\e[m\]\[\e[1;36m\]@\[\e[m\]\[\e[1;35m\]\h\[\e[m\]:\w]\n\$ "
实际效果是这样
乍一看好唬人,但如果把他拆开来看就简单了,其实上面的这些可以简化为 PS1='\u@\h \w \n\$'这样看就简单了,其他的就只是颜色了
\u 是用户 \h 第一个主机名 \w 目录 \n 换行 \$ 提示符,这些参数很简单 直接 man bash 找PS1 就能找到
man bash
......
\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
\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
..........
下面就是颜色部分了,看起来挺复杂的,其实就是把上面那些参数用 \[\e[F;Bm\] 和 \[\e[m\] 包在里面,再来个简单的组合就变成了 PS1="\[\e[37;1m\]\u\[\e[m\]" 其他的部分可以按照需要向里面添加 如果不是特殊符号的话是可以直接放上去的例如()和[]。
可以测试下效果,呵呵是不是提示符消失了?没关系这里没有加export 不会影响其他终端的。上面的F Bm是前景和背景的颜色,我这里有个列表,是在eol.cn上面找到的。这里偷懒就直接贴上来了
前景 背景 颜色
---------------------------------------
30 40 黑色
31 41 紅色
32 42 綠色
33 43 黃色
34 44 藍色
35 45 紫紅色
36 46 青藍色
37 47 白色
代码 意义
-------------------------
0 OFF
1 高亮显示
4 underline
5 闪烁
7 反白显示
8 不可见
阅读(1000) | 评论(0) | 转发(0) |