I have written a script that I think a lot of people online would enjoy using. Anyone who's used ANSI color codes to add colorized output to terminal programs or shell scripts knows how painful it is to have to open up some thread on Github or Stackoverflow with a table of color codes and keep referring back to it every time you want to use a new color. Wouldn't it be nice to have some terminal-based program that would do this for you?
Ladies and gentlemen, I believe I have solved this problem.
The solution is a script I wrote called
color. Here's some example output:
$ color red \e[0;31m : Red \e[1;31m : Red bold \e[4;31m : Red underline \e[41m : Red background \e[0;91m : Red high intensity \e[1;91m : Red bold high intensity \e[0;101m : Red high intensity background
When run in the terminal, the printed color code is styled with the background and color that it represents. Screenshot
Note: if a
NO_COLOR environment variable is set, the program does not use ANSI color escape sequences to color its output. See no-color.org for more information.
The script can be found in this directory on my scripts page. However, keep in mind that the script depends on a file called
colors.txt saved in
~/.local/share. To make it easier on you, here's the set of commands to install the script and its dependency file:
curl -s https://spitemim.xyz/scripts/color/color > ~/.local/bin/color chmod +x ~/.local/bin/color curl -s https://spitemim.xyz/scripts/color/colors.txt > ~/.local/share/colors.txt
The script doesn't print the reset code correctly. Just memorize
\e[0;0m and you won't have to worry about it.
The script now prints the reset sequence normally. Turns out I missed a backslash in colors.txt...