finga-utils/birthdays/birthdays.sh
finga 2093a4fbc2 Add 'birthdays/' from commit 'b273fa4b1150fa0c90a6de810f514b1d7523e82e'
git-subtree-dir: birthdays
git-subtree-mainline: 6e3b60e406
git-subtree-split: b273fa4b11
2020-04-23 18:52:56 +02:00

34 lines
1.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 -lt "$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
elif [ "$days" -eq 0 ];then
echo -e "\033[31;5m$(cut -f2- <<< "$i") is today\033[0m"
fi
done