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颜色编码,运行这个命令可以直接看到
ln@ln-PC:~/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