Colorful echo
for unix-like shell ( ascii color only ), decorate your terminal with more colors.
A light, self-adapting wrapper of echo
with several useful features, makes easy work for changing foreground, background and text action ( highlight, underline, blink ... ).
Before use cecho
, simply source it in your .zshrc
or .bashrc
, or any shell script you want to colorize:
source /path/to/cecho.sh
Support multi-string in one command:
cecho -color1 message1 [ -color2 message2 ... ] [ -done ]
Support setting foreground, background and action
cecho -fg_color -bg_color -action message [...] [ -done ]
All switches have two forms, short for convenience, long for readability.
The short forms are the abbreviation from the corresponding long forms.
short | long |
---|---|
-r | -red |
-g | -green |
-y | -yellow |
-b | -blue |
-p | -purple |
-c | -cyan |
-w | -white |
-gr | -gray |
-bk | -black |
short | long |
---|---|
-br | -b_red |
-bg | -b_green |
-by | -b_yellow |
-bb | -b_blue |
-bp | -b_purple |
-bc | -b_cyan |
-bw | -b_white |
-bgr | -b_gray |
-bbk | -b_black |
short | long |
---|---|
-d | -done |
-hl | -highlight |
-ul | -underline |
-re | -reverse |
-bl | -blink |
-iv | -invisible |
short | long |
---|---|
-B | -blank |
-t | -tab |
-n | -newline |
short | long |
---|---|
-h | -help,--help |
cecho -r "hello world ! "
or
cecho -red "hello world ! "
or
cecho -r hello -B world -B !
cecho -r -t hello -B world -n !
cecho -r -by -hl "hello world ! "
set [ red, yellow, highlight & underline ] for "hello", [ cyan, red, reverse ] for "world", [ green, black, blink ] for "!" :
cecho -r -by -hl -ul hello -d -B -c -br -re world -d -B -g -bl !
Please refer to the help file for more examples:
cecho -h
That colorful help page is generated by cecho
.
Once you have sourced cecho
, CECHO_IS_IMPORTED=1
will be defined.
That meams you can check this var CECHO_IS_IMPORTED
to confirm if you are in a no_cecho env or not:
Exp: Sence 2
If you want to deactive cecho
temporarily, set CECHO_IS_INACTIVE=1
before calling cecho
.
Note: color and action can be disabled by CECHO_IS_INACTIVE
, but return
, blank
and tab
are still active, as you wish.
No need to do any change, cecho
can self-adapt this: colorful for stdout, non-colorful for file/pipe.
Don't be disappointed, you only need to modify your script like this:
if [ -z "$CECHO_IS_IMPORTED" ]
then
echo hello world
else
cecho -r -bg -hl hello -B world
fi
Or shortly:
[ -z "$CECHO_IS_IMPORTED" ] && echo "hello world" || cecho -r -bg -hl hello -B world
CECHO_IS_INACTIVE=1
cecho -r -bg -hl hello world # <-- now cecho is inactive
CECHO_IS_INACTIVE=
cecho -r -bg -hl hello world # <-- now cecho is active
- Action flag
-d
( same as-done
) will turn off all settings ( fg, bg and action ), Thus, in single command, you have to set flags again to retrive it back once there are other strings after-d
. - Some special characters ( with centain format ) don't work properly, such as
cecho "!"
. It's due toecho
... usececho '!'
orcecho !
instead. - It's not necessary to use
-d
at the begin/end of commands,cecho
will take care of it. - Actions can overlaied.
Another C version project is coprintf.