Add "new" command implementation

This commit is contained in:
The Magician 2023-12-08 17:18:24 +00:00
parent 621340140e
commit ab5425d59d
2 changed files with 41 additions and 1 deletions

View File

@ -12,6 +12,9 @@ teardown() {
}
test__zk_new_creates_file_in_correct_directory() {
fake "$EDITOR" echo ""
fake vi echo ""
export ZKDIR="$TMP_ZETTELKASTEN"
filename="aaaaaaaaaaaaaa"
fake date "echo $filename"
@ -20,3 +23,34 @@ test__zk_new_creates_file_in_correct_directory() {
assert "test -e $TMP_ZETTELKASTEN/$filename"
}
test__zk_new_runs_EDITOR_if_EDITOR_is_set() {
export EDITOR="nano"
# shellcheck disable=SC2016
fake "$EDITOR" echo '$EDITOR ${FAKE_PARAMS[@]}'
export ZKDIR="$TMP_ZETTELKASTEN"
filename="aaaaaaaaaaaaaa"
fake date "echo $filename"
expected="$EDITOR $TMP_ZETTELKASTEN/$filename"
result="$(_zk_new)"
assert_equals "$expected" "$result"
}
test__zk_new_runs_vi_if_EDITOR_is_not_set() {
export EDITOR=""
# shellcheck disable=SC2016
fake vi echo 'vi ${FAKE_PARAMS[@]}'
export ZKDIR="$TMP_ZETTELKASTEN"
filename="aaaaaaaaaaaaaa"
fake date "echo $filename"
expected="vi $TMP_ZETTELKASTEN/$filename"
result="$(_zk_new)"
assert_equals "$expected" "$result"
}

8
zk
View File

@ -1,7 +1,7 @@
#!/bin/sh
ZKDIR="$HOME/.local/share/zk/"
COMMANDS='list new delete'
COMMANDS='list new'
get_command() {
commands="$1"
@ -27,6 +27,12 @@ _zk_list() {
_zk_new() {
filename="$(_zk_isosec)"
touch "$ZKDIR/$filename"
if test -n "$EDITOR"; then
$EDITOR "$ZKDIR/$filename"
else
vi "$ZKDIR/$filename"
fi
}
main() {