Add "new" command implementation
This commit is contained in:
parent
621340140e
commit
ab5425d59d
|
@ -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
8
zk
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue