News for hackers. Stuff that matters.
Re:ANSI escape codes (2019) by chasil on Wednesday February 03, 2021 @11:06AM (#26014943)
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
Re:ANSI escape codes (2019) by JNRowe on Wednesday February 03, 2021 @02:28PM (#26018002)
This 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/...

² http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-...

³ http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-...