多彩终端或控制台?

多彩终端或控制台?

我喜欢控制台中的颜色,我想知道是否有任何方法可以让终端(我猜只有软件能够做到这一点)以颜色打印几乎所有内容。当然有这些--color=auto东西,但它适用于一些命令(lsgrep...?)。我想要的是更加丰富多彩的东西,它也适用于不使用颜色的命令,我不知道这是否可能。

例如,Windows 版的 MobaXTerm(类似 Cygwin)使用了大量颜色。当然,它不仅是一个终端,而且是一个完整的软件(另一层)......也许这是获得严肃色彩的唯一方法?

任何线索将不胜感激。

答案1

感谢大家的回复,但没有人符合我的需求。我想要一些非侵入性的东西,我在 CW 中找到了它。这是一个很好的软件,您需要将其添加到路径的开头。当然,它并不适用于每个命令(仅适用于已经定义的命令),但结果看起来非常好!如果您有兴趣,请查看:http://freecode.com/projects/cw

答案2

您还可以使用应付为了这。

cop 是输出到终端的程序的包装器,为它们提供实用和美观的颜色,同时在文本级别保持它们相同。

答案3

尝试测试一下:

for i in {0..7};
do
    tput setaf $i;
    echo "tput setaf $i";
    tput sgr0;
done

查看终端代码和内容:http://www.bash-hackers.org/wiki/doku.php/scripting/terminalcodes

答案4

首先,关于一般颜色,您可能会对这个脚本感兴趣。它在控制台中工作正常(在终端中,制表符宽度未正确设置)。

#!/bin/bash

setterm -regtabs 4
Color_names="bla red gre yel blu mag cya whi"
Color_arr=($Color_names)

tput setaf 4
tput setab 7
echo -n "            normal             "
tput sgr0

echo -n " "

tput setaf 7
tput setab 4   
echo "            bright             "

tput sgr0
for cmd in sgr0 bold
do
    tput $cmd
    for m in 0 1 2 3 4 5 6 7
    do
        tput setaf $m
        echo -n ${Color_arr[$m]}" "
    done
done
echo

tput sgr0
cat /sys/module/vt/parameters/default_red \
    /sys/module/vt/parameters/default_grn \
    /sys/module/vt/parameters/default_blu | sed s/,0/", "/g | \
    sed s/^0/" "/g | \
    tr "," "\t"

其次,您可以使用 ls 做更多事情,而不仅仅是--color=auto.但是,需要做一些工作才能解决所有问题。我编写了一个脚本来促进理解,并以系统的方式对文件进行着色(基于其扩展名)。

如果太长无法粘贴,请检查一下这里

#!/bin/bash

# must be sourced

# see `man dircolors`
# in particular `dircolors -p > coldb.txt` (-p, --print-database)

# attributes
# 00 = none
# 01 = bold (bright)
# 04 = underscore (white; disables color code)
# 05 = blink (gray background)
# 07 = reverse (color as background)
# 08 = concealed (doesn't do anything)

# colors
R='00;31' # red
G='00;32' # green
Y='00;33' # yellow (brown in my console)
B='00;34' # blue
M='00;35' # magenta
C='00;36' # cyan
W='00;37' # white

# bold (bright)
BR='01;31' # red
BG='01;32' # green
BY='01;33' # yellow
BB='01;34' # blue
BM='01;35' # magenta
BC='01;36' # cyan
BW='01;37' # white

# for di (below) and possible some others
BL='00;30' # black
GR='01;30' # gray

# background
BGBL='40' # blue
BGRE='41' # red
BGGR='42' # green
BGYE='43' # yellow
BGBL='44' # blue
BGMA='45' # magenta
BGCY='46' # cyan
BGWH='47' # white

RS="rs=0"         # reset
DI="di=$BB"       # directory
LN="ln=$C"        # link
MH="mh=00"        # multihardlink (file with more than one link)
PI="pi=$BY;$BGBL" # pipe (FIFO)
SO="so=$BM"       # socket
DO="do=$BM"       # door
BD="bd=$BY;$GBBL" # block device driver
CD="cd=$BY;$BGBL" # character device driver
OR="or=$BR"       # symlink to nonexistent (or non-stat'able) file
SU="su=$W;$BGRE"  # file that is setuid (u+s)
SG="sg=$BL;$BGYE" # file that is setgid (g+s)
CA="ca=$BL;$BGRE" # file with capability
TW="tw=$BL;$BGGR" # dir that is sticky and other-writable (+t,o+w)
OW="ow=$BB;$BGGR" # dir that is other-writable (o+w) and not sticky
ST="st=$BW;$BGBL" # sticky bit dir (+t) and not other-writable
EX="ex=$BG"       # file with execute permission

ARCHIVE="*.tar=$BR:*.tgz=$BR:*.arj=$BR:*.taz=$BR:*.lzh=$BR:*.lzma=$BR:*.tlz=$BR:*.txz=$BR:*.zip=$BR:*.z=$BR:*.Z=$BR:*.dz=$BR:*.gz=$BR:*.lz=$BR:*.xz=$BR:*.bz2=$BR:*.bz=$BR:*.tbz=$BR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