From e2d532927685109d2b92be64608482bd00337314 Mon Sep 17 00:00:00 2001 From: lew Date: Thu, 2 Apr 2026 18:55:15 +0100 Subject: [PATCH] feat: snooze command with basic ID support --- nag | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ test/snooze.bats | 28 ++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/snooze.bats diff --git a/nag b/nag index ccc025c..dc911e3 100755 --- a/nag +++ b/nag @@ -45,6 +45,7 @@ NAG_CMD="${NAG_CMD:-notify-send}" # Sound file to play when an alarm fires. Empty or missing file = no sound. NAG_SOUND="${NAG_SOUND-/usr/share/sounds/freedesktop/stereo/bell.oga}" _MUTE_FILE="${NAG_DIR}/mute" +_SNOOZED_FILE="${NAG_DIR}/snoozed" # The default subcommand if no args are passed. NAG_DEFAULT="${NAG_DEFAULT:-list}" @@ -1236,6 +1237,7 @@ Usage: ${_ME} tag add tags to an alarm ${_ME} tag list alarms with a tag ${_ME} untag remove tags from an alarm + ${_ME} snooze [] snooze alarms ${_ME} check check and fire due alarms ${_ME} mute mute alarm sounds ${_ME} unmute unmute alarm sounds @@ -1947,6 +1949,70 @@ unmute() { fi } +# snooze ###################################################################### + +describe "snooze" < [] + +Description: + Snooze alarms to prevent them from firing. Snoozed alarms stay in the + alarm file but are skipped by check. With "all", snoozes every alarm. + With an ID, snoozes that alarm. With a tag, snoozes all alarms with + that tag. Optional duration sets an automatic expiry. + +Examples: + ${_ME} snooze all snooze everything + ${_ME} snooze 3 snooze alarm 3 + ${_ME} snooze work snooze all [work] alarms + ${_ME} snooze 3 "2 weeks" snooze alarm 3 for 2 weeks + ${_ME} snooze all "July 15" snooze everything until July 15 +HEREDOC +snooze() { + local _target="${1:-}" + [[ -n "${_target}" ]] || _exit_1 printf "Usage: %s snooze []\\n" "${_ME}" + + # "all" and tag: placeholder for Task 5. + if [[ "${_target}" == "all" ]] + then + _exit_1 printf "Not yet implemented.\\n" + fi + + if [[ ! "${_target}" =~ ^[0-9]+$ ]] + then + _exit_1 printf "Not yet implemented.\\n" + fi + + # Numeric: snooze by ID. + _acquire_lock + _read_alarms + + local _found=0 _message="" _line + for _line in "${_ALARMS[@]:-}" + do + [[ -n "${_line}" ]] || continue + local _id + _id="${_line%%$'\t'*}" + if [[ "${_id}" == "${_target}" ]] + then + _found=1 + _message="$(_get_alarm_field "${_line}" 5)" + break + fi + done + + if (( ! _found )) + then + _release_lock + _exit_1 printf "No alarm with ID %s.\\n" "${_target}" + fi + + _ensure_nag_dir + printf "%s\\n" "${_target}" >> "${_SNOOZED_FILE}" + _release_lock + printf "Snoozed [%s] %s.\\n" "${_target}" "${_message}" +} + # edit ######################################################################## describe "edit" <