2014-07-13 04:35:12 +02:00
|
|
|
#!/bin/bash
|
2020-01-07 17:08:18 +01:00
|
|
|
set -e
|
2014-07-13 04:35:12 +02:00
|
|
|
|
2019-11-16 14:38:55 +01:00
|
|
|
conf_file="$HOME/.birthdays"
|
2014-07-13 04:35:12 +02:00
|
|
|
days_left=30
|
|
|
|
|
2020-01-07 17:08:18 +01:00
|
|
|
# read file into line seperated string array (could become sorted)
|
2014-07-13 04:40:22 +02:00
|
|
|
readarray lines < "$conf_file"
|
|
|
|
|
2020-01-07 17:08:18 +01:00
|
|
|
# iterate over each field
|
2014-07-13 04:40:22 +02:00
|
|
|
for i in "${lines[@]}"; do
|
2020-01-07 17:08:18 +01:00
|
|
|
# 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
|
2020-04-23 18:52:49 +02:00
|
|
|
if [ 0 -lt "$days" ] && [ "$days" -le "$days_left" ];then
|
2020-01-07 17:08:18 +01:00
|
|
|
# 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
|
2018-10-27 01:55:36 +02:00
|
|
|
else
|
2020-01-07 17:08:18 +01:00
|
|
|
echo -e "\\033[32m$(cut -f2- <<< "$i") in $days days\\033[m"
|
2018-10-27 01:55:36 +02:00
|
|
|
fi
|
2020-04-23 18:52:49 +02:00
|
|
|
elif [ "$days" -eq 0 ];then
|
|
|
|
echo -e "\033[31;5m$(cut -f2- <<< "$i") is today\033[0m"
|
2014-07-13 04:35:12 +02:00
|
|
|
fi
|
|
|
|
done
|