Call _zk_edit from _zk_new
This commit is contained in:
parent
416d837307
commit
0a32609d2d
|
@ -30,3 +30,32 @@ test__zk_edit_uses__zk_search_when_filename_not_passed_as_parameter() {
|
|||
|
||||
assert_equals "$expected" "$result"
|
||||
}
|
||||
|
||||
test__zk_edit_runs_EDITOR_if_EDITOR_is_set() {
|
||||
export EDITOR="nano"
|
||||
# shellcheck disable=SC2016
|
||||
fake "$EDITOR" echo '$EDITOR ${FAKE_PARAMS[@]}'
|
||||
fake vi cat
|
||||
|
||||
filename="11111111111111"
|
||||
expected="$EDITOR $ZKDIR/$filename"
|
||||
|
||||
result="$(_zk_edit $filename)"
|
||||
|
||||
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="11111111111111"
|
||||
fake date "echo $filename"
|
||||
expected="vi $TMP_ZETTELKASTEN/$filename"
|
||||
|
||||
result="$(_zk_edit $filename)"
|
||||
|
||||
assert_equals "$expected" "$result"
|
||||
}
|
||||
|
|
|
@ -12,45 +12,25 @@ teardown() {
|
|||
}
|
||||
|
||||
test__zk_new_creates_file_in_correct_directory() {
|
||||
fake "$EDITOR" echo ""
|
||||
fake vi echo ""
|
||||
|
||||
export ZKDIR="$TMP_ZETTELKASTEN"
|
||||
filename="aaaaaaaaaaaaaa"
|
||||
filename="11111111111111"
|
||||
fake date "echo $filename"
|
||||
fake _zk_edit echo ""
|
||||
|
||||
_zk_new
|
||||
|
||||
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[@]}'
|
||||
|
||||
test__zk_new_runs_zk_edit_on_new_file() {
|
||||
export ZKDIR="$TMP_ZETTELKASTEN"
|
||||
filename="aaaaaaaaaaaaaa"
|
||||
fake date "echo $filename"
|
||||
expected="$EDITOR $TMP_ZETTELKASTEN/$filename"
|
||||
filename="11111111111111"
|
||||
# shellcheck disable=SC2016
|
||||
fake _zk_edit echo '_zk_edit ${FAKE_PARAMS[@]}'
|
||||
fake _zk_isosec echo "$filename"
|
||||
expected="_zk_edit $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"
|
||||
}
|
||||
|
||||
|
|
11
zk
11
zk
|
@ -31,12 +31,7 @@ _zk_search() {
|
|||
_zk_new() {
|
||||
filename="$(_zk_isosec)"
|
||||
touch "$ZKDIR/$filename"
|
||||
|
||||
if test -n "$EDITOR"; then
|
||||
$EDITOR "$ZKDIR/$filename"
|
||||
else
|
||||
vi "$ZKDIR/$filename"
|
||||
fi
|
||||
_zk_edit "$filename"
|
||||
}
|
||||
|
||||
_zk_edit() {
|
||||
|
@ -46,7 +41,11 @@ _zk_edit() {
|
|||
filename="$(_zk_search)"
|
||||
fi
|
||||
|
||||
if test -n "$EDITOR"; then
|
||||
$EDITOR "$ZKDIR/$filename"
|
||||
else
|
||||
vi "$ZKDIR/$filename"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
Loading…
Reference in New Issue