Skip to content

Commit 5906f92

Browse files
authored
Merge pull request #20 from paulbellamy/master
Fixing some bugs with space-handling in directories.
2 parents 32395e9 + 7cee6f1 commit 5906f92

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

notes

+4-4
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() {
@@ -46,7 +46,7 @@ grep_notes() {
4646

4747
new_note() {
4848
note_name="$*"
49-
mkdir -p $(dirname "$notes_dir/$note_name")
49+
mkdir -p "$(dirname "$notes_dir/$note_name")"
5050
open_note "$note_name.md"
5151
}
5252

@@ -154,7 +154,7 @@ main() {
154154
esac
155155
shift
156156

157-
$cmd $@
157+
$cmd "$@"
158158
ret=$[$ret+$?]
159159
exit $ret
160160
}

test/test-find.bats

+11-1
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

+15-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,18 @@ notes="./notes"
4141

4242
assert_success
4343
assert_exists "$NOTES_DIRECTORY/note with spaces.md"
44-
}
44+
}
45+
46+
@test "Should create notes within subfolders with spaces" {
47+
run $notes new "subfolder with spaces/note"
48+
49+
assert_success
50+
assert_exists "$NOTES_DIRECTORY/subfolder with spaces/note.md"
51+
}
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)