3 ms·
This is my korn-shell fragment that I use to set up color codes. Everything but the final print is posix-compliant (change it to a printf to run under bash).
by chasil 6y ago
This is my korn-shell fragment that I use to set up color codes. Everything but the final print is posix-compliant (change it to a printf to run under bash).
N='\033[' x=30
for a in Bl R G Y B M C W # 4-bit Black Red Green Yellow Blue Magenta Cyan White
do eval $a='$N'"'"$(( x ))"m'" \
b$a='$N'"'"$((60+x ))"m'" \
${a}bg='$N'"'"$((10+x ))"m'" \
b${a}bg='$N'"'"$((70+x++))"m'" # bX=bright Xbg=background bXbg=brgt bgnd
done
N=$N'0m' x=0
print $bB'This is bright blue.'$N
- JNRowe 6y agoThis is one of the many cool things that zsh comes with out of the box. It ships an autoload-able colors¹ script that does largely the same thing as your fragment, but you know it available wherever zsh is. In much the same way it comes with both a termcap² and terminfo³ module, allowing you to easily avoid hardcoding system specific escapes in to your config. ¹ https://github.com/zsh-users/zsh/blob/master/Functions/Misc/colors https://github.com/zsh-users/zsh/blob/master/Functions/Misc/... ² http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002ftermcap-Module http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-... ³ http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fterminfo-Module http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-...