From 7aa8c71d49f4856e6844082f5c4a3c2082a7e6bd Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Tue, 15 Dec 2020 14:40:40 +0100 Subject: [PATCH] less error outpouts if no appointment --- .local/bin/statusbar/appointments | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.local/bin/statusbar/appointments b/.local/bin/statusbar/appointments index b3a183b..544c92f 100755 --- a/.local/bin/statusbar/appointments +++ b/.local/bin/statusbar/appointments @@ -2,16 +2,19 @@ #Print the next appointment for the day for statusbar #or generate notification for upcoming appointment diff=$(calcurse --next | tail -n1 | sed 's/^\s*//; s/\[//;s/\]//' | cut -f1 -d ' ') -secs=$(( $(echo "$diff" | cut -f1 -d ':') * 3600 + $(echo "$diff" | cut -f2 -d ':') *60 )) -time_appointment="$(date --date "@$(( $( date +'%s' ) + $secs ))" +"%s")" -appointment="$(calcurse --next | tail -n1 | awk '{$1=""; print $0}' | sed 's/^\s*//')" -if [ "$1" = "notif" ]; then - msg="$(printf '%s\n%s' "$(date --date "@$time_appointment" +'%H:%M')" "$appointment")" - notify-send "Appointment coming up" "$msg" -else - midnight=$(( $(date --date "$(date | sed 's/..:..:../23:59:59/; s/ PM//; s/ AM//')" +%s) + 1 )) - if [ $midnight -gt "$time_appointment" ]; then - printf '%s %s' "$(date --date "@$time_appointment" +'%H:%M')" "$appointment" +if [ -n "$diff" ]; then + secs=$(( $(echo "$diff" | cut -f1 -d ':') * 3600 + $(echo "$diff" | cut -f2 -d ':') *60 )) + time_appointment="$(date --date "@$(( $( date +'%s' ) + $secs ))" +"%s")" + appointment="$(calcurse --next | tail -n1 | awk '{$1=""; print $0}' | sed 's/^\s*//')" + if [ "$1" = "notif" ]; then + msg="$(printf '%s\n%s' "$(date --date "@$time_appointment" +'%H:%M')" "$appointment")" + notify-send "Appointment coming up" "$msg" + else + midnight=$(( $(date --date "$(date | sed 's/..:..:../23:59:59/; s/ PM//; s/ AM//')" +%s) + 1 )) + if [ $midnight -gt "$time_appointment" ]; then + printf '%s %s' "$(date --date "@$time_appointment" +'%H:%M')" "$appointment" + fi fi +else printf '\n' fi