Lolcat is a great color tool for the shell. I will show you how I use it to increase my shell productivity.
Consider some wall of text output (like from journalctl)
Is it not much easier to read with colors and numbered lines. The colors help tell your brain how much of the line you have finished reading and the white numbered lines tell you which line you are on.
This can be achieved with lolcat
First download lolcat
- Ubuntu Install: https://www.howtoinstall.me/ubuntu/18-04/lolcat/
- Centos / Redhat: https://www.tecmint.com/lolcat-command-to-output-rainbow-of-colors-in-linux-terminal/
After installing, make sure lolcat is available to be called directly without absolute path. Make sure you symlink it to any of your PATHs like /usr/local/bin.
My lolcat installed to /usr/games/lolcat. And /usr/games is not part of my environment PATH variable
So I ran: # ln -s /usr/games/local /usr/local/bin/lolcat
Then I added to my shell start up script ( ~/.bashrc , ~/.zshrc , etc… ), the following
alias lesslol=’lolcat -f | less -r’
alias lol=’lolcat -f’
alias nlol=’lolcat -f | nl’
Sidenote: check that your less -r works. Your system might have a limited version of less (busybox less). If lesslol or if less -r returns that it does not work, then download less and it will overwrite the limited less with the better gnu less: apt-get install less
Instead of calling it with lolcat, call it with lol which is lolcat -f. The -f option allows the colors to be piped to the next item. Without it lolcat will only show colors if its stdout is a TTY / terminal. However if the stdout is a pipe then lolcat removes the colors, unless -f option is used.
Now use lol to output colored version of your text. nlol to output white number lines of your text and the text will be in color. Then use lesslol to get your text into a PAGER with colors.
Now to get the output seen above. I just pipe anything to nlol,
It works on static files
It works on scrolling output
cat file.txt | nlol
Unfortunately, nlol file.txt does not work because and will output text format. Look at the nlol alias to see why. The file.txt portion attaches to the nl and not the lolcat part
journalctl -f | nlol
journalctl | nlol
cat anything | nlol
And it also works with less. Note for less to show colors you have to pipe in -r option (which outputs raw control characters; remember coloring in the shell is done via raw control characters). If you want to see all of the raw control chars just run this lol file.txt | cat -a or lol file.txt | less
cat file.txt | lesslol
If you want to see number lines, less has the -N option, so you can just append it to lesslol.
cat file.txt | lesslol -N