From d73ebdbddd5ad9548ec46c0358d7a81cf6b82531 Mon Sep 17 00:00:00 2001 From: lew Date: Thu, 2 Apr 2026 16:57:05 +0100 Subject: [PATCH] feat: interactive confirmation for tagged stop and skip --- README.md | 4 ++-- nag | 44 ++++++++++++++++++++++++++++++++++++-------- test/skip.bats | 4 ++-- test/stop.bats | 4 ++-- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7a430eb..94e5a21 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Usage: nag stop Description: - Stop an alarm by ID, or stop all alarms with a tag (requires -f). + Stop an alarm by ID, or stop all alarms with a tag. ``` #### `nag skip` @@ -151,7 +151,7 @@ Usage: Description: Skip the next occurrence of a repeating alarm (reschedule without firing). For one-shot alarms, this deletes them. With a tag, applies to all - matching alarms (requires -f). + matching alarms. ``` #### `nag tag` diff --git a/nag b/nag index b380fbe..c50c815 100755 --- a/nag +++ b/nag @@ -1303,7 +1303,7 @@ Usage: ${_ME} stop Description: - Stop an alarm by ID, or stop all alarms with a tag (requires -f). + Stop an alarm by ID, or stop all alarms with a tag. HEREDOC stop() { local _target="${1:-}" @@ -1385,9 +1385,23 @@ _stop_by_tag() { if (( ! _YES )) then - _release_lock - printf "Would stop %s alarm(s) tagged [%s]. Pass -f to confirm.\\n" "${#_matched[@]}" "${_tag}" - return 0 + if _interactive_input + then + printf "Stop %s alarm(s) tagged [%s]? [y/N] " "${#_matched[@]}" "${_tag}" + local _reply + read -r _reply + case "${_reply}" in + [yY]*) ;; + *) + _release_lock + return 0 + ;; + esac + else + _release_lock + printf "Stop %s alarm(s) tagged [%s]? Pass -f to confirm.\\n" "${#_matched[@]}" "${_tag}" + return 0 + fi fi if (( ${#_new_alarms[@]} == 0 )) @@ -1419,7 +1433,7 @@ Usage: Description: Skip the next occurrence of a repeating alarm (reschedule without firing). For one-shot alarms, this deletes them. With a tag, applies to all - matching alarms (requires -f). + matching alarms. HEREDOC skip() { local _target="${1:-}" @@ -1513,9 +1527,23 @@ _skip_by_tag() { if (( ! _YES )) then - _release_lock - printf "Would skip %s alarm(s) tagged [%s]. Pass -f to confirm.\\n" "${_match_count}" "${_tag}" - return 0 + if _interactive_input + then + printf "Skip %s alarm(s) tagged [%s]? [y/N] " "${_match_count}" "${_tag}" + local _reply + read -r _reply + case "${_reply}" in + [yY]*) ;; + *) + _release_lock + return 0 + ;; + esac + else + _release_lock + printf "Skip %s alarm(s) tagged [%s]? Pass -f to confirm.\\n" "${_match_count}" "${_tag}" + return 0 + fi fi for _line in "${_ALARMS[@]:-}" diff --git a/test/skip.bats b/test/skip.bats index cba4dba..915a8e1 100644 --- a/test/skip.bats +++ b/test/skip.bats @@ -36,9 +36,9 @@ load test_helper @test "skip by tag requires -f" { run_nag every day "tomorrow 3pm" "daily work" run_nag tag 1 work - run "${_NAG}" skip work + run "${_NAG}" skip work < /dev/null [ "${status}" -eq 0 ] - [[ "${output}" =~ "Would skip" ]] + [[ "${output}" =~ "Skip" ]] [[ "${output}" =~ "-f" ]] } diff --git a/test/stop.bats b/test/stop.bats index 732fc0a..1b5e9ae 100644 --- a/test/stop.bats +++ b/test/stop.bats @@ -36,9 +36,9 @@ load test_helper @test "stop by tag requires -f" { run_nag at "tomorrow 3pm" "tagged alarm" run_nag tag 1 work - run "${_NAG}" stop work + run "${_NAG}" stop work < /dev/null [ "${status}" -eq 0 ] - [[ "${output}" =~ "Would stop" ]] + [[ "${output}" =~ "Stop" ]] [[ "${output}" =~ "-f" ]] [ -s "${NAG_DIR}/alarms" ] }