Thursday, May 20, 2021

A pretty, pretty cal(endar): Rev1

In my last blog post, I provided a BASH function that can operate as a lightweight replacement for cal. When I say "replacement", I mean, it just gives cal a bit of a facelift by making it pretty.

I'm here today to post a patch to that function. The regex got wonky when matching 20 or 21, so the header with the month and the year got dirty.


I also got tired of seeing the double-spaces at the end of the current week. That has only been an issue with the Apple version of cal. However, with some regex revisions, we arrive at a once again pretty, pretty cal(endar).

Somehow, my blog got marked as a malware-potential-phishing-don't-go-there-it's-Knockturn-Alley (please don't sue me, J.K.!) website because of my last post. To avoid this from happening again, I'm instead going to post links to the scripts and the patch (so you can see the diff).

 I have tested this out quite thoroughly on macOS and Linux, but do keep in mind that YMMV.

Again, standard attribution CC license applies to this code.


Link #1: v1 of the function

Link #2: v2 of the function

Link #2: The patch file

 

Until next time ...

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