Mac GeekeryGet your geek on. |
|
blog advertising is good for you
recent popular content
User login
|
Just a tiny little one-liner I came up with that I thought I’d share. It works great with GeekTool. cal | sed "s/^/ /;s/$/ /;s/ $(date +%d) / $(date +%d | sed 's/./#/g') /" It displays the regular unix calendar, but with the current date replaced by #‘s. Like this:
December 2005
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 ## 20 21 22 23 24
25 26 27 28 29 30 31
Nothing big, and I’m sure you already knew how to do this, but you never know UPDATE: cal | sed "s/^/ /;s/$/ /;s/ $(date +%d) /$(printf '\e[1m&\e[m')/"
About 31d1
|
Very cool.
And the best hacks use the most common tools in ways that may seem obvious, but weren’t to anyone else before, so keep going.
—
cp
Here’s a version that’s a tad simpler:
And here’s one that, instead of replacing with ##, replaces with inverted colors. It can be easily adjusted to use some other highlight instead:
The [[:<:]] thing only seems to work on my Mac – it throws an error on my Debian box and Cygwin. I’m trying to find it in the documentation, I mean, I can see what it does but haven’t a clue why!
But man, thanks for the escape code knowledge. I was trying to figure this out yesterday and couldn’t for the life of me. \e[ is power!
Odd. the [[:<:]] thing is documented in re_format(7). But I guess I’m not terribly surprised it’s not universal – I had never even heard of this particular character class until I read re_format(7) in search of it (I tried \< and \b first and neither worked, so I read docs).
As for escape codes. You could also use V[ to embed a raw escape code into the line. I just used the printf version so you could copy&paste directly from the web page (since raw escape codes can’t be embedded into webpages).
I had a problem where dates with single digits didn’t work.
For me, the fix was to change the $(date +%d) call to:
$(date +%e)
-HI-