Add util
This commit is contained in:
parent
0f2e13d15b
commit
9d8609b1b4
10
README.txt
10
README.txt
|
@ -42,6 +42,16 @@ $ farend -l 100 -q /tmp/todo
|
|||
# … 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
|
||||
————————————————————————————————————————
|
||||
|
|
|
@ -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 $@
|
Ŝarĝante…
Reference in New Issue