Implement edit command

This commit is contained in:
The Magician 2023-12-08 18:09:21 +00:00
parent d2405b8b3b
commit 416d837307
2 changed files with 42 additions and 0 deletions

32
tests/test__zk_edit.sh Normal file
View File

@ -0,0 +1,32 @@
#!/bin/bash
setup() {
source ../zk
}
test__zk_edit_uses_filename_when_passed_as_parameter() {
# shellcheck disable=SC2016
fake vi 'echo vi "${FAKE_PARAMS[@]}"'
export EDITOR=""
zettel_name="11111111111111"
expected="vi $ZKDIR/$zettel_name"
result="$(_zk_edit $zettel_name)"
assert_equals "$expected" "$result"
}
test__zk_edit_uses__zk_search_when_filename_not_passed_as_parameter() {
export EDITOR=""
zettel_name="11111111111111"
expected="vi $ZKDIR/$zettel_name"
# shellcheck disable=SC2016
fake vi 'echo vi "${FAKE_PARAMS[@]}"'
fake _zk_search echo "$zettel_name"
result="$(_zk_edit)"
assert_equals "$expected" "$result"
}

10
zk
View File

@ -39,6 +39,16 @@ _zk_new() {
fi fi
} }
_zk_edit() {
filename="$1"
if test -z "$filename"; then
filename="$(_zk_search)"
fi
vi "$ZKDIR/$filename"
}
main() { main() {
subcommand="$(get_command "$ZKCOMMANDS" "$1")" subcommand="$(get_command "$ZKCOMMANDS" "$1")"
_zk_"$subcommand" _zk_"$subcommand"