davidktw
Arch-Supremacy Member
- Joined
- Apr 15, 2010
- Messages
- 13,550
- Reaction score
- 1,301
Hi guys,
I have been playing around geek tool and its really astounding how much we could customize our mac. I have been stealing codes from google but my calendar is still misaligned haha. The numbers and the day are abit misalign for the single digit.
the code is :
cal | sed -E '1,$'"s/ ($(date +%e))( |$)/ $(echo '\033[1;32m')\1$(echo '\033[0m')\2/"
anyhow knows what is the code for a aligned calendar with the current day coloured?
Thanks a lot !!
This is not pertaining to Mac OS X, that would be Unix variant related. However you will want to change your code to the following in Mac OS X
Code:
cal | sed -E '3,$'"s/[[:<:]]($(date +%e))[[:>:]]/$(echo -e '\033[1;32m')\1$(echo -e '\033[0m')/"
Anyway, this is not customising anything, just a command with manipulation.
Your RE may not work for all possible calendar dates, which I have explained below.
I have made a few changes, first the introduction of "-e" to the echo command will allow the escape codes. This is not found in the echo manual, but rather in the bash manual, depending on which shell you are using. While I have not really exhaustively figure out, it could be some shell doesn't support "echo" natively and requires an external command.
Next is I change the addresses lines matched for sed, it is good to start with line 3 instead of line 1, since line 1 and 2 are not where the dates are found. Not that your $(date +%e) will produce anything beyond 31, but it's always good to be more concise with the application of regular expressions.
I have also corrected the way you match for date numbers. You should use the word boundaries instead of detected of preceding and trailing of space or EOL, since for dates that start at the first column will not match. Word boundaries will be a better choice for the text output by "cal"
Are you a student or already working ? Anyway good try. Seldom see anyone asking about such in-depth stuffs around here
On Linux, you will want to use
Code:
cal | sed -E '3,$'"s/\b($(date +%e))\b/$(echo -e '\033[1;32m')\1$(echo -e '\033[0m')/"
For something more cross unices compatible, try this instead
Code:
cal | perl -pne "s/\b`date +%e`\b/\033[1;32m$&\033[0m/"
Last edited:
