Friday, May 14, 2021

A pretty, pretty cal(endar)

I live on the command-line and that means I need tools to keep me efficient. One tool that I use frequently is "cal". However, the default output is quite plain and (at times) is hard to read. So, I slapped together a shell function that colorizes the output and makes using it at-a-glance much easier.

The default output looks like this:


With colorized output, it now looks like this:

I always have a terminal session open with an active SSH connection to my Linux box, and another terminal session open for conducting business locally on my Mac. So, I needed this to work for both Mac and Linux. I learned the hard way that "echo -e" is really only useful on a Linux system. Thus, I have started using "printf" when I want formatted output beyond a simple "echo". I should probably revise this function to use "tput" and such, but for now I'm using ANSI escape codes for coloring text.

For macOS, you'll want to place this function in your ~/.bash_profile. On your Linux box, storing it in ~/.bashrc should be fine.

It probably goes without saying, this is provided to you without any warranty or guarantee, etc., etc., feel free to use or redistribute. Attribution would be nice, but not really necessary unless it's being included in something proprietary or a for-profit solution. Nonetheless, enjoy! 

 

Link #1: A pretty, pretty cal(endar) v1


Until next time!


Ref: https://misc.flogisoft.com/bash/tip_colors_and_formatting