diff --git a/nag b/nag index a78beb2..b80424c 100755 --- a/nag +++ b/nag @@ -304,6 +304,9 @@ do -h|--help) _SUBCOMMAND="help" ;; + -e|--edit) + _SUBCOMMAND="edit" + ;; --version) _SUBCOMMAND="version" ;; @@ -1046,12 +1049,14 @@ Usage: ${_ME} stop delete alarm ${_ME} skip skip next occurrence ${_ME} check check and fire due alarms + ${_ME} edit edit alarms file directly ${_ME} mute mute alarm sounds ${_ME} unmute unmute alarm sounds ${_ME} help [] show help ${_ME} version show version Options: + -e, --edit Edit alarms file directly. --yes Skip all prompts. --version Show version. @@ -1474,5 +1479,20 @@ unmute() { fi } +# edit ######################################################################## + +describe "edit" < "${_ALARMS_FILE}" + "${EDITOR:-${VISUAL:-vi}}" "${_ALARMS_FILE}" +} + # _main must be called after everything has been defined. _main diff --git a/test/edit.bats b/test/edit.bats new file mode 100644 index 0000000..b183c04 --- /dev/null +++ b/test/edit.bats @@ -0,0 +1,31 @@ +#!/usr/bin/env bats + +load test_helper + +@test "edit creates alarms file if missing" { + [[ ! -f "${NAG_DIR}/alarms" ]] + EDITOR="true" run_nag edit + [[ "$status" -eq 0 ]] + [[ -f "${NAG_DIR}/alarms" ]] +} + +@test "edit opens the alarms file in EDITOR" { + write_alarm "1 9999999999 test alarm" + EDITOR="cat" run_nag edit + [[ "$status" -eq 0 ]] + [[ "$output" == *"test alarm"* ]] +} + +@test "-e flag invokes edit" { + write_alarm "1 9999999999 test alarm" + EDITOR="cat" run_nag -e + [[ "$status" -eq 0 ]] + [[ "$output" == *"test alarm"* ]] +} + +@test "--edit flag invokes edit" { + write_alarm "1 9999999999 test alarm" + EDITOR="cat" run_nag --edit + [[ "$status" -eq 0 ]] + [[ "$output" == *"test alarm"* ]] +}