xshell , securecrt ANSI 顏色配置;shell 終端 ASNI顏色 配置詳解
使用xshell securecrt 時,可以自定義顏色主題檔案, 但是各個顏色塊都代表什麼意思呢?
搜尋linux下檔案顏色的含義,也沒看到一個講清楚的,比如說
藍色表示目錄;綠色表示可執行檔案;紅色表示壓縮檔案;淺藍色表示連結檔案;白色表示其他檔案;黃色是裝置檔案,包括block, char, fifo。
但是內部原理是什麼呢?現在想要改變xshell中目錄的顯示顏色,在ASNI顏色設定中 ,總共有16個顏色塊, 哪一個代表目錄的顏色呢?
如圖
ASNI定義了幾種基本顏色的編碼
Black: \u001b[30m. Red: \u001b[31m. Green: \u001b[32m. Yellow: \u001b[33m. Blue: \u001b[34m. Magenta: \u001b[35m. Cyan: \u001b[36m. White: \u001b[37m. #30(黑色)、31(紅色)、32(綠色)、 33(黃色)、34(藍色)、35(洋紅)、36(青色)、37(白色)
下面是個人理解, 有問題請指出
第一行每一個色塊分別對應上面的8個編碼,第二行分別對應加粗字型。
30顏色對應第一個色塊, 37顏色對應第8個色塊
例如, 把第一行第二個色塊,改為白色,表示 31 編碼的顏色,在xshell中將顯示為白色。
第三方工具的設定ASNI顏色, 本質上就是把預定好這八種顏色,顯示為其他顏色。
如果某個檔案,顏色型別為39, 超出了這八種基本顏色,則顯示為原本編碼好的ASNI顏色
不同型別檔案的ASNI顏色編碼,執行這個命令可以直接看到
[email protected]:~/1src/shell$ dircolors -p # Configuration file for dircolors, a utility to help you set the # LS_COLORS environment variable used by GNU ls with the --color option. # Copyright (C) 1996-2017 Free Software Foundation, Inc. # Copying and distribution of this file, with or without modification, # are permitted provided the copyright notice and this notice are preserved. # The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the # slackware version of dircolors) are recognized but ignored. # Below are TERM entries, which can be a glob patterns, to match # against the TERM environment variable to determine if it is colorizable. TERM Eterm TERM ansi TERM *color* TERM con[0-9]*x[0-9]* TERM cons25 TERM console TERM cygwin TERM dtterm TERM gnome TERM hurd TERM jfbterm TERM konsole TERM kterm TERM linux TERM linux-c TERM mlterm TERM putty TERM rxvt* TERM screen* TERM st TERM terminator TERM tmux* TERM vt100 TERM xterm* # Below are the color init strings for the basic file types. A color init # string consists of one or more of the following numeric codes: # Attribute codes: # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed # Text color codes: # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white # Background color codes: # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white #NORMAL 00 # no color code at all #FILE 00 # regular file: use no color at all RESET 0 # reset to "normal" color DIR 01;34 # directory LINK 01;36 # symbolic link. (If you set this to 'target' instead of a # numerical value, the color is as for the file pointed to.) MULTIHARDLINK 00 # regular file with more than one link FIFO 40;33 # pipe SOCK 01;35 # socket DOOR 01;35 # door BLK 40;33;01 # block device driver CHR 40;33;01 # character device driver ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file ... MISSING 00 # ... and the files they point to SETUID 37;41 # file that is setuid (u+s) SETGID 30;43 # file that is setgid (g+s) CAPABILITY 30;41 # file with capability STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w) OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable # This is for files with execute permission: EXEC 01;32 # List any file extensions like '.gz' or '.tar' that you would like ls # to colorize below. Put the extension, a space, and the color init string. # (and any comments you want to add after a '#') # If you use DOS-style suffixes, you may want to uncomment the following: #.cmd 01;32 # executables (bright green) #.exe 01;32 #.com 01;32 #.btm 01;32 #.bat 01;32 # Or if you want to colorize scripts even if they do not have the # executable bit actually set. #.sh 01;32 #.csh 01;32 # archives or compressed (bright red) .tar 01;31 .tgz 01;31 .arc 01;31 .arj 01;31 .taz 01;31 .lha 01;31 .lz4 01;31 .lzh 01;31 .lzma 01;31 ... etc
舉例分析
DIR 01;34 # directory
定義了目錄檔案使用 34 編碼, 在標準終端中, 顯示顏色是藍色
現在想要目錄在xshell中的顯示為綠色,由於目錄顏色為34編碼,對應第5個色塊(30對應第一個色塊), 則在ASNI設定中點選 第一行第五個色塊, 在色板中選中綠色, 那麼目錄檔案將顯示為綠色。
假如出現了例外,執行 dircolors -p 顯示 DIR 01;35 # directory
那麼目錄的ASNI顏色是35 , 則想要修改目錄的顯示顏色,則需要點 第一行第六個色塊。
到這裡終於可以明明白白的修改顏色顯示了。
dircolors 命令實際操作的是環境變數 $LS_COLORS
下面是一個指令碼檔案,列印顯示所有已定義的顏色規則
#!/bin/bash
# For LS_COLORS, print type and description in the relevant color.
IFS=:
for ls_color in $LS_COLORS; do
color="${ls_color#*=}"
type="${ls_color%=*}"
# Add descriptions for named types.
case "$type" in
bd) type+=" (block device)" ;;
ca) type+=" (file with capability)" ;;
cd) type+=" (character device)" ;;
di) type+=" (directory)" ;;
do) type+=" (door)" ;;
ex) type+=" (executable file)" ;;
fi) type+=" (regular file)" ;;
ln) type+=" (symbolic link)" ;;
mh) type+=" (multi-hardlink)" ;;
mi) type+=" (missing file)" ;;
no) type+=" (normal non-filename text)" ;;
or) type+=" (orphan symlink)" ;;
ow) type+=" (other-writable directory)" ;;
pi) type+=" (named pipe, AKA FIFO)" ;;
rs) type+=" (reset to no color)" ;;
sg) type+=" (set-group-ID)" ;;
so) type+=" (socket)" ;;
st) type+=" (sticky directory)" ;;
su) type+=" (set-user-ID)" ;;
tw) type+=" (sticky and other-writable directory)" ;;
esac
# Separate each color with a newline.
if [[ $color_prev ]] && [[ $color != $color_prev ]]; then
echo
fi
printf "\e[%sm%s\e[m " "$color" "$type"
# For next loop
color_prev="$color"
done
echo
執行這個指令碼,可以看到不同型別的檔案的顯示效果不同。
參考連結 http://www.cnblogs.com/xlmeng1988/archive/2013/01/08/shell_color.html
http://blog.chinaunix.net/uid-26021340-id-3481924.html
https://askubuntu.com/questions/17299/what-do-the-different-colors-mean-in-ls