This commit is contained in:
Jaidyn Levesque 2020-01-26 00:58:57 -06:00
parent 0f2e13d15b
commit 9d8609b1b4
2 changed files with 72 additions and 0 deletions

View File

@ -42,6 +42,16 @@ $ farend -l 100 -q /tmp/todo
# … usage goes on along those lines. # … usage goes on along those lines.
————————————————————————————————————————
UTILS
————————————————————————————————————————
The "utils/" folder contains some stuff I personally find useful that's related
to the project.
Right now, it just contains `ccal`, a frontend to `cal` that portably
highlights the current day (since it's not builtin in many versions).
———————————————————————————————————————— ————————————————————————————————————————
BORING STUFF BORING STUFF
———————————————————————————————————————— ————————————————————————————————————————

62
util/ccal.sh Executable file
View File

@ -0,0 +1,62 @@
#!/bin/sh
# --------------------------------------
# name: ccal
# desc: portable colourized `cal`
# main: jaidyn ann <jadedctrl@teknik.io>
# --------------------------------------
# On some systems, the `cal` command can't highlight the current day.
# This version does it portably, only assuming you have POSIX `cal`.
# To change the highlight colours, set the $CCAL_HEAD and $CCAL_TAIL
# variables. $CCAL_HEAD should set the colours (ANSI codes etc), _TAIL should
# reset colours, ofc.
# Return today's date, YYYY-MM-DD
function today {
date +"%Y-%m-%d"
}
# Return the day of a given date
function date_day {
local date="$1"
echo "$date" \
| awk -F "-" '{print $3}'
}
# Concatenate three arguments into one non-delimited string
function join_three {
a="$1"
b="$2"
c="$3"
echo "${a}${b}${c}"
}
# Color the given text from piped input, using giving head and tail as codes
function colour_text {
local text="$1"
local head="$2"
local tail="$3"
sed 's%'"$text"'%'"$(join_three "$head" "$text" "$tail")"'%'
}
# Colourized form of `cal`
function colourized_cal {
cal $@ \
| colour_text "$(date_day "$(today)")" "$CCAL_HEAD" "$CCAL_TAIL"
}
# Set colours if you haven't
if test -z "$CCAL_HEAD"; then
white_bg="$(tput setab 7 2>/dev/null)"
black_fg="$(tput setaf 0 2>/dev/null)"
bold="$(tput bold 2>/dev/null)"
reset="$(tput sgr0)"
CCAL_HEAD="${white_bg}${black_fg}${bold}"
CCAL_TAIL="${reset}"
fi
colourized_cal $@