refactor and add comments
This commit is contained in:
parent
9143df0017
commit
fc00f7696b
24
birthdays.sh
24
birthdays.sh
|
@ -1,19 +1,31 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
conf_file="$HOME/.birthdays"
|
conf_file="$HOME/.birthdays"
|
||||||
days_left=30
|
days_left=30
|
||||||
|
|
||||||
|
# read file into line seperated string array (could become sorted)
|
||||||
readarray lines < "$conf_file"
|
readarray lines < "$conf_file"
|
||||||
|
|
||||||
|
# iterate over each field
|
||||||
for i in "${lines[@]}"; do
|
for i in "${lines[@]}"; do
|
||||||
days=$(( 10#$(date -d "$( cut -f 1 <<< "$i" )" +%j 2>/dev/null || echo 59) - 10#$(date +%j) ))
|
# 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 [ 0 -le "$days" ] && [ "$days" -le "$days_left" ];then
|
||||||
if [ "$days" -le $((days_left / 2)) ] && [ ! "$days" -le 7 ];then
|
# if $days is between less than 8: output red counter
|
||||||
echo -e "\\033[33m$( cut -f 2- <<< "$i" ) in $days days\\033[m"
|
if [ "$days" -le 7 ];then
|
||||||
elif [ "$days" -le 7 ];then
|
echo -e "\\033[31m$(cut -f2- <<< "$i") in $days days\\033[m"
|
||||||
echo -e "\\033[31m$( cut -f 2- <<< "$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
|
else
|
||||||
echo -e "\\033[32m$( cut -f 2- <<< "$i" ) in $days days\\033[m"
|
echo -e "\\033[32m$(cut -f2- <<< "$i") in $days days\\033[m"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue