diff --git a/scripts/reminder.sh b/scripts/reminder.sh index 5dff7a5..cc4ccbd 100755 --- a/scripts/reminder.sh +++ b/scripts/reminder.sh @@ -36,6 +36,44 @@ add_custom_reminder() { } +add_daily_reminder() { + info="$(yad --form --selectable-labels \ + --title "I38 - New Daily Reminder" \ + --field="Reminder Text" "" \ + --field="Select Hour:":num '1!1..12' \ + --field="Select Minute:":num '0!0..59' \ + --field="Select AM or PM":cb 'AM!PM' \ + --button="Cancel:1" \ + --button="Create Reminder:0")" + + # Properly handle window close events. + if [[ $? -eq 1 || $? -eq 252 ]]; then + return + fi + + # Get information for reminder into an array + IFS='|' read -a reminder <<< $info + + # Fix time to be 2 digits. + [[ ${#reminder[1]} -eq 1 ]] && reminder[1]="0${reminder[1]}" + [[ ${#reminder[2]} -eq 1 ]] && reminder[2]="0${reminder[2]}" + + # Make sure we have reminder text + if [[ ${#reminder[0]} -lt 3 ]]; then + error "No reminder text given, addition canceled." + return + fi + reminderEntry="REM AT ${reminder[1]}:${reminder[2]}${reminder[3]} +5 REPEAT daily MSG ${reminder[0]} %2." + echo "# Added by I38." >> ~/.reminders + echo "$reminderEntry" >> ~/.reminders + if [[ -N ~/.reminders ]]; then + message "Reminder added." + else + error "Something went wrong. The reminder was not added." + fi +} + + add_monthly_reminder() { info="$(yad --form --selectable-labels \ --title "I38 - New Monthly Reminder" \ @@ -201,6 +239,21 @@ view_reminders() { done } + +view_today() { + if ! [[ -r ~/.reminders ]]; then + error "No reminders found." + return + fi + + mapfile -t lines < <(rem | tr -s $'\n') + # Display the reminders + yad --list --title "I38 - Reminders" --text "Today's reminders:" \ + --column "Reminder" "${lines[@]}" \ + --button="Close!gtk-ok:0" +} + + if ! command -v remind &> /dev/null ; then error "Please install remind. For notifications, please make sure to have notification-daemon and notify-send as well. Run i38.sh to regenerate your i3 config after the needed components are installed." exit 1 @@ -214,31 +267,41 @@ fi while : ; do action=$(yad --title "I38 - Reminders" --form \ - --button="_View Reminders!gtk-info":2 \ - --button="_Add Weekly Reminder!gtk-ok":0 \ - --button="Add Monthly Reminder!gtk-ok":3 \ - --button="Add Custom Reminder!gtk-edit":4 \ + --button="_View Today's Reminders!gtk-info":2 \ + --button="_View All Reminders!gtk-info":3 \ + --button="_Add Daily Reminder!gtk-ok":0 \ + --button="_Add Weekly Reminder!gtk-ok":4 \ + --button="Add Monthly Reminder!gtk-ok":5 \ + --button="Add Custom Reminder!gtk-edit":6 \ --button="Close!gtk-cancel":1 \ --separator="") case $? in 0) - # Handle "Add Weekly Reminder" button click - add_weekly_reminder + # Handle "Add Daily Reminder" button click + add_daily_reminder ;; 1|252) # Handle "Close" button click and escape. exit 0 ;; 2) + # View today's reminders + view_today + ;; + 3) # View reminders view_reminders ;; - 3) + 4) + # Handle "Add Weekly Reminder" button click + add_weekly_reminder + ;; + 5) # Handle "Add Monthly Reminder" button click add_monthly_reminder ;; - 4) + 6) # Handle "Add Custom Reminder" button click add_custom_reminder ;;