8

I love colors in my console, and I wonder if there is any way to get a terminal (I guess only a software is able to do that) printing almost everything in colors. Of course there is the --color=auto things, but it works for a few commands (ls, grep...?). What I would want, is something way more colorful, that works also for commands that are not made to use colors, I don't know if it's possible.

For instance, there is MobaXTerm for Windows (something like Cygwin) which uses a lot of color. Of course it's not only a terminal, but a complete software (another layer)... maybe it's the only way to get something seriously colorized?

Any clue would be really appreciated.

3

6 Answers 6

6

Thank guys for all the replies, but no one matched my needs. I wanted something non-intrusive, and I found it in cw. This is a nice soft that you need to add in the begining of your PATH. So of course, it doesn't work with every command (only the ones already defined), but the result looks very nice! Check it out if you're interested: http://freecode.com/projects/cw

3

You can also use cope for this.

cope is a wrapper around programs that output to a terminal, to give them colour for utility and aesthetics while still keeping them the same at the text level.
1
  • Thank for that solution. It's almost the same thing than 'cw', except that, IMO, cw is easier to install. But it's same colors and almost same fields highlight. Moreover, cw has almost a hundred of possible commands, whereas cope has ~40. Nov 23, 2012 at 14:05
2

Try testing this :

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

See terminalcodes and stuff: http://www.bash-hackers.org/wiki/doku.php/scripting/terminalcodes

1

Something I've often done is pipe the output of commands or log files that don't use colour themselves through a little script that colourizes them according to rules matching certain text. Perl is particularly good at this.

Here's a little example:

#!/usr/bin/perl -n

BEGIN {
  $exp = shift @ARGV;
  $color = shift @ARGV;
  die "Use: colourize regexp colour" unless $color;
}

if (/$exp/) {
  print"\e[${color}m";
}

print;

if (/$exp/) {
  print "\e[0m";
}

Save this as colourize somewhere in your PATH, chmod +x it and you can do things like

command | colourize WARNING 31

to have all lines containing WARNING printed in red. The number 31 is the ANSI colour code for red.

0

First, concerning colors in general, this script might interest you. It works fine in the console (in a terminal, the tab width doesn't get set correctly).

#!/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"

Second, you can do a lot more with ls than just --color=auto. But, it requires some work to sort everything out. I wrote a script to facilitate understanding, as well as to colorize files (based on their extensions) in a systematic way.

If it's too long to be pasted, check it out here.

#!/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:*.tbz2=$BR:*.tz=$BR:*.deb=$BR:*.rpm=$BR:*.jar=$BR:*.war=$BR:*.ear=$BR:*.sar=$BR:*.rar=$BR:*.ace=$BR:*.zoo=$BR:*.cpio=$BR:*.7z=$BR:*.rz=$BR"
IMAGE="*.jpg=$BM:*.jpeg=$BM:*.gif=$BM:*.bmp=$BM:*.pbm=$BM:*.pgm=$BM:*.ppm=$BM:*.tga=$BM:*.xbm=$BM:*.xpm=$BM:*.tif=$BM:*.tiff=$BM:*.png=$BM:*.svg=$BM:*.svgz=$BM:*.mng=$BM:*.pcx=$BM"
MOVIE="*.mov=$M:*.mpg=$M:*.mpeg=$M:*.m2v=$M:*.mkv=$M:*.webm=$M:*.ogm=$M:*.mp4=$M:*.m4v=$M:*.mp4v=$M:*.vob=$M:*.qt=$M:*.nuv=$M:*.wmv=$M:*.asf=$M:*.rm=$M:*.rmvb=$M:*.flc=$M:*.avi=$M:*.fli=$M:*.flv=$M:*.gl=$M:*.dl=$M:*.xcf=$M:*.xwd=$M:*.yuv=$M:*.cgm=$M:*.emf=$M:*.axv=$M:*.anx=$M:*.ogv=$M:*.ogx=$M"
AUDIO="*.aac=$BM:*.au=$BM:*.flac=$BM:*.mid=$BM:*.midi=$BM:*.mka=$BM:*.mp3=$BM:*.mpc=$BM:*.ogg=$BM:*.ra=$BM:*.wav=$BM:*.axa=$BM:*.oga=$BM:*.spx=$BM:*.xspf=$BM:"
SOURCE="*.el=$BC:*.c=$BC:*.cpp=$BC"
TEXT="*.txt=$BW"
PDF="*.pdf=$R"
WEB="*.html=$Y:*.htm=$Y:*.css=$W;$BGMA"

TYPES="$ARCHIVE:$IMAGE:$MOVIE:$AUDIO:$SOURCE:$TEXT:$PDF:$WEB"

LS_COLORS="$RS:$DI:$LN:$MH:$PI:$SO:$DO:$BD:$CD:$OR:$SU:$SG:$CA:$TW:$OW:$ST:$EX:"$TYPES

export LS_COLORS
0

There is a nice blog post about colorizing the terminal. Except for using built in color support in different tools it recommends grc, the Generic Colouriser. If you are on a Debian based system you can install it via

sudo apt-get install grc

You can then use give a command you want to colorize as argument to grc, e.g.

grc head /var/log/syslog

This relies on configuration in /etc/grc.conf being able to choose a proper configuration file to colorize head /var/log/syslog with. In this case it works because there are lines in /etc/grc.conf that directs grc to the correct configuration file, i.e. conf.log.

If one wants to force a particular configuration file on a particular output one can use grcat, e.g.

git diff | grcat conf.diff

which colorizes the output of git diff with the configuration file conf.diff. The configuration files I have mentioned are default ones that comes with the packages but one can obviously make own configurations.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .