Skip to content

Commit

Permalink
Merge pull request pimterry#20 from paulbellamy/master
Browse files Browse the repository at this point in the history
Fixing some bugs with space-handling in directories.
  • Loading branch information
pimterry authored Dec 4, 2016
2 parents 32395e9 + 7cee6f1 commit 5906f92
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
8 changes: 4 additions & 4 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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

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

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

find_notes() {
Expand Down Expand Up @@ -46,7 +46,7 @@ grep_notes() {

new_note() {
note_name="$*"
mkdir -p $(dirname "$notes_dir/$note_name")
mkdir -p "$(dirname "$notes_dir/$note_name")"
open_note "$note_name.md"
}

Expand Down Expand Up @@ -154,7 +154,7 @@ main() {
esac
shift

$cmd $@
$cmd "$@"
ret=$[$ret+$?]
exit $ret
}
Expand Down
12 changes: 11 additions & 1 deletion test/test-find.bats
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ notes="./notes"

assert_success
assert_output "path with spaces/note.md"
}
}

@test "Should find files inside notes directories with spaces" {
mkdir "$NOTES_DIRECTORY/path with spaces"
touch "$NOTES_DIRECTORY/path with spaces/note.md"

NOTES_DIRECTORY="$NOTES_DIRECTORY/path with spaces" run $notes find

assert_success
assert_output "note.md"
}
16 changes: 15 additions & 1 deletion test/test-new.bats
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ notes="./notes"

assert_success
assert_exists "$NOTES_DIRECTORY/note with spaces.md"
}
}

@test "Should create notes within subfolders with spaces" {
run $notes new "subfolder with spaces/note"

assert_success
assert_exists "$NOTES_DIRECTORY/subfolder with spaces/note.md"
}

@test "Should create notes within note directories with spaces" {
NOTES_DIRECTORY="$NOTES_DIRECTORY/notes with spaces" run $notes new "note"

assert_success
assert_exists "$NOTES_DIRECTORY/notes with spaces/note.md"
}

0 comments on commit 5906f92

Please sign in to comment.