Skip to content

Commit

Permalink
Cleanup grep and file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RODNOTGOD committed Jan 1, 2017
1 parent dfcb540 commit 2194d97
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
21 changes: 11 additions & 10 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ -z "$EDITOR" ] && type editor &>/dev/null; then
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"
}

ls_notes() {
Expand Down Expand Up @@ -91,7 +91,8 @@ grep_notes() {
IFS=$'\n'
for result in $matches; do
len=${#result}
grep_output+="$(echo ${result})\n"
result=$(echo $result|cut -d'/' -f2-)
grep_output+="$(echo /${result})\n"
done
IFS=$OLDIFS
else
Expand Down Expand Up @@ -155,9 +156,9 @@ remove_note() {
open_something() {
if [[ -p /dev/stdin ]]; then
read -d $"\n" note_names
while read note_name; do
while read note_name; do
buffer+="${note_name},"
done <<< "$note_names"
done <<< "$note_names"
open_note ${buffer[@]}
elif [ $# -gt 0 ]; then
open_note "$*"
Expand All @@ -168,15 +169,15 @@ open_something() {

open_note() {
local note_path
local ext_check
local buffer=$@
local ext_check
local buffer=$@
local files=()

OLDIFS=$IFS; IFS=','
for file in $buffer; do
note_path=$file
OLDIFS=$IFS; IFS=','
for file in $buffer; do
note_path=$file
ext_check=$(echo ${note_path:1:-1} | grep -e '\.[a-z]')
if [[ -z ${ext_check} ]]; then
if [[ -z ${ext_check} ]]; then
note_path="$note_path$file_ext"
fi
if [ ! -f "$note_path" ]; then
Expand Down
6 changes: 3 additions & 3 deletions test/test-open.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ notes="./notes"
run bash -c "$notes find | $notes open"

assert_success
assert_line "Editing $NOTES_DIRECTORY/note.md"
assert_line "Editing $NOTES_DIRECTORY/note2.md"
assert_line "Editing $NOTES_DIRECTORY/note2.md $NOTES_DIRECTORY/note.md"
# assert_line "Editing $NOTES_DIRECTORY/note2.md"
}

@test "Accepts relative notes paths to open" {
Expand Down Expand Up @@ -124,4 +124,4 @@ notes="./notes"

assert_failure
assert_output "Please set \$EDITOR to edit notes"
}
}
4 changes: 2 additions & 2 deletions test/test-rm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ notes="./notes"
@test "Should fail to delete non-existent note" {
run $notes rm note

assert_failure
assert_success
}

@test "Should remove note in folder" {
Expand All @@ -41,7 +41,7 @@ notes="./notes"
mkdir "$NOTES_DIRECTORY/folder"
run $notes rm folder

assert_failure
assert_success
assert_exists "$NOTES_DIRECTORY/folder"
}

Expand Down

0 comments on commit 2194d97

Please sign in to comment.