Skip to content

Commit e44434d

Browse files
authored
Merge pull request #41 from primis/master
Bugfix: Notes fails if NOTES_DIRECTORY doesn't exist
2 parents d19057f + 0892768 commit e44434d

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

notes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ configured_dir=${NOTES_DIRECTORY%/} # Remove trailing slashes
1212
notes_dir="${configured_dir:-$HOME/notes}"
1313
escaped_notes_dir="$(printf "$notes_dir" | sed -e 's/[]\/$*.^|[]/\\&/g')"
1414

15+
# Make sure the notes directory actually exists, and create it if it doesn't
16+
if [ ! -d "$notes_dir" ]; then
17+
mkdir -p "$notes_dir"
18+
fi
19+
1520
# If no $EDITOR, look for `editor` (symlink on debian/ubuntu/etc)
1621
if [ -z "$EDITOR" ] && type editor &>/dev/null; then
1722
EDITOR=editor

test/test-base.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!./test/libs/bats/bin/bats
2+
3+
load 'libs/bats-support/load'
4+
load 'libs/bats-assert/load'
5+
load 'helpers'
6+
7+
setup() {
8+
setupNotesEnv
9+
}
10+
11+
teardown() {
12+
teardownNotesEnv
13+
}
14+
15+
export EDITOR=touch
16+
notes="./notes"
17+
18+
@test "NOTES_DIRECTORY should be created if it doesn't exist" {
19+
rm -r $NOTES_DIRECTORY
20+
run $notes new test
21+
assert_success
22+
assert_exists "$NOTES_DIRECTORY/test.md"
23+
}

test/test-config.bats

100644100755
File mode changed.

test/test-ls.bats

100644100755
File mode changed.

0 commit comments

Comments
 (0)