finga-utils/birthdays.sh
2020-01-07 20:31:41 +01:00

32 lines
1 KiB
Bash
Executable file

#!/bin/bash
set -e
conf_file="$HOME/.birthdays"
days_left=30
# read file into line seperated string array (could become sorted)
readarray lines < "$conf_file"
# iterate over each field
for i in "${lines[@]}"; do
# get date
date=$(cut -d" " -f1 <<< "$i")
# calculate days from now until $date if date fails it could be 2/29
days=$(( 10#$(date -d "$date" +%j 2>/dev/null || echo 059) - 10#$(date +%j) ))
# if $days is in range of $days_left
if [ 0 -le "$days" ] && [ "$days" -le "$days_left" ];then
# if $days is between less than 8: output red counter
if [ "$days" -le 7 ];then
echo -e "\\033[31m$(cut -f2- <<< "$i") in $days days\\033[m"
# if $days is between 8-15: output yellow counter
elif [ "$days" -le $((days_left / 2)) ];then
echo -e "\\033[33m$(cut -f2- <<< "$i") in $days days\\033[m"
# else print green counter
else
echo -e "\\033[32m$(cut -f2- <<< "$i") in $days days\\033[m"
fi
fi
done