Skip to content

Commit 7cee6f1

Browse files
committed
Fixing bugs around NOTE_DIRECTORY having spaces
1 parent 381b32a commit 7cee6f1

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

notes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
configured_dir=${NOTES_DIRECTORY%/} # Remove trailing slashes
44
notes_dir="${configured_dir:-$HOME/notes}"
5-
escaped_notes_dir=$(printf $notes_dir | sed -e 's/[]\/$*.^|[]/\\&/g')
5+
escaped_notes_dir="$(printf "$notes_dir" | sed -e 's/[]\/$*.^|[]/\\&/g')"
66

77
# If no $EDITOR, look for `editor` (symlink on debian/ubuntu/etc)
88
if [ -z "$EDITOR" ] && type editor &>/dev/null; then
99
EDITOR=editor
1010
fi
1111

1212
without_notes_dir() {
13-
cat | sed -e s/^$escaped_notes_dir//g | sed -E "s/^\/+//g"
13+
cat | sed -e "s/^$escaped_notes_dir//g" | sed -E "s/^\/+//g"
1414
}
1515

1616
find_notes() {

test/test-find.bats

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,14 @@ notes="./notes"
8181

8282
assert_success
8383
assert_output "path with spaces/note.md"
84-
}
84+
}
85+
86+
@test "Should find files inside notes directories with spaces" {
87+
mkdir "$NOTES_DIRECTORY/path with spaces"
88+
touch "$NOTES_DIRECTORY/path with spaces/note.md"
89+
90+
NOTES_DIRECTORY="$NOTES_DIRECTORY/path with spaces" run $notes find
91+
92+
assert_success
93+
assert_output "note.md"
94+
}

test/test-new.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ notes="./notes"
4949
assert_success
5050
assert_exists "$NOTES_DIRECTORY/subfolder with spaces/note.md"
5151
}
52+
53+
@test "Should create notes within note directories with spaces" {
54+
NOTES_DIRECTORY="$NOTES_DIRECTORY/notes with spaces" run $notes new "note"
55+
56+
assert_success
57+
assert_exists "$NOTES_DIRECTORY/notes with spaces/note.md"
58+
}

0 commit comments

Comments
 (0)