Linux實現彩色提示符

更改用戶目錄下的.bashrcbash

加入:less

export PS1='\[\e[33m\][\u@\h:\W]\$ \[\e[m\]' 

例如:字體

 1 # .bashrc 
 2  
 3 # User specific aliases and functions 
 4  
 5 alias rm='rm -i' 
 6 alias cp='cp -i' 
 7 alias mv='mv -i' 
 8 export PS1='\[\e[33m\][\u@\h:\W]\$ \[\e[m\]' 
 9  
10 # Source global definitions 
11 if [ -f /etc/bashrc ]; then 
12         . /etc/bashrc 
13 fi 
14  
15 # less man page colors 
16 export GROFF_NO_SGR=1 
17 export LESS="FRSXQ" 
18 export LESS_TERMCAP_mb=$'\E[01;31m' 
19 export LESS_TERMCAP_md=$'\E[01;31m' 
20 export LESS_TERMCAP_me=$'\E[0m' 
21 export LESS_TERMCAP_so=$'\E[01;44;33m' 
22 export LESS_TERMCAP_se=$'\E[0m' 
23 export LESS_TERMCAP_us=$'\E[01;32m' 
24 export LESS_TERMCAP_ue=$'\E[0m' 
25  
26 # grep colors 
27 export GREP_OPTIONS='--color=auto' 
28 export GREP_COLOR='1;32' 
29  
30 export TERMINFO=/usr/share/terminfo 
31 #export TERM=xterm-256color 33  
34 export HISTIGNORE="&:[bf]g:exit" 
35 export HISTCONTROL=ignoredups 
36 export HISTFILESIZE=10000 
37 export HISTSIZE=10000 
38 export HISTTIMEFORMAT="%F %T " 

 

其中提示符表達的意思爲:spa

'\[\e[33m\][\u@\h:\W]\$ \[\e[m\]'

\[\e[33m\] 表示把字體顏色設爲(shi)黃色
[\u@\h:\W]\$ 表示用戶@host工做目錄$

效果如圖:

醒目的(shi)黃色,媽媽不再用擔憂我找不到提示符了~

附顏色列表:
\[\e[F;Bm\], 其中 F 爲字體顏色,編號30~37; B 爲背景色,編號40~47
可經過 \[\e[m\] 關閉顏色輸出(不要問我爲何括號不是匹配的。。。);以及當B爲0~8時,將顯示帶有樣式的字體。
 

顏色表 

前景 背景 顏色
---------------------------------------
30 40 黑色
31 41 紅色
32 42 綠色
33 43 黃色
34 44 藍色
35 45 紫紅色
36 46 青藍色
37 47 白色

樣式代碼 意義
-------------------------
0     OFF
1     高亮顯示
4     underline
5     閃爍
7     反白顯示
8     不可見
相關文章
相關標籤/搜索