feat: edit subcommand, for editing the alarm file directly
This commit is contained in:
parent
7abbf0625a
commit
72cca4da11
2 changed files with 51 additions and 0 deletions
20
nag
20
nag
|
|
@ -304,6 +304,9 @@ do
|
|||
-h|--help)
|
||||
_SUBCOMMAND="help"
|
||||
;;
|
||||
-e|--edit)
|
||||
_SUBCOMMAND="edit"
|
||||
;;
|
||||
--version)
|
||||
_SUBCOMMAND="version"
|
||||
;;
|
||||
|
|
@ -1046,12 +1049,14 @@ Usage:
|
|||
${_ME} stop <id> delete alarm
|
||||
${_ME} skip <id> 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 [<subcommand>] 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" <<HEREDOC
|
||||
Usage:
|
||||
${_ME} ( edit | -e | --edit )
|
||||
|
||||
Description:
|
||||
Open the alarms file in \$EDITOR (falls back to \$VISUAL, then vi).
|
||||
HEREDOC
|
||||
edit() {
|
||||
_ensure_nag_dir
|
||||
[[ -f "${_ALARMS_FILE}" ]] || : > "${_ALARMS_FILE}"
|
||||
"${EDITOR:-${VISUAL:-vi}}" "${_ALARMS_FILE}"
|
||||
}
|
||||
|
||||
# _main must be called after everything has been defined.
|
||||
_main
|
||||
|
|
|
|||
31
test/edit.bats
Normal file
31
test/edit.bats
Normal file
|
|
@ -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"* ]]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue