Skip to content

Commit 83ca5f2

Browse files
committed
Allow passing files names directly to open
1 parent 236bfc8 commit 83ca5f2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

notes

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,24 @@ open_something() {
5151
while read note_name; do
5252
open_note "$note_name"
5353
done <<< "$note_names"
54+
elif [ $# -gt 0 ]; then
55+
open_note "$*"
5456
else
5557
open $notes_dir
5658
fi
5759
}
5860

5961
open_note() {
60-
$EDITOR "$notes_dir/$1" < /dev/tty
62+
note_path=$1
63+
64+
if [[ "$note_path" != *.md ]]; then
65+
note_path="$note_path.md"
66+
fi
67+
if [ ! -f "$note_path" ]; then
68+
note_path="$notes_dir/$note_path"
69+
fi
70+
71+
$EDITOR "$note_path" < /dev/tty
6172
}
6273

6374
usage() {

test/test-open.bats

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,22 @@ notes="./notes"
5353
assert_success
5454
assert_line "Editing $NOTES_DIRECTORY/note.md"
5555
assert_line "Editing $NOTES_DIRECTORY/note2.md"
56+
}
57+
58+
@test "Accepts relative notes paths to open" {
59+
touch $NOTES_DIRECTORY/note.md
60+
61+
run bash -c "$notes open note.md"
62+
63+
assert_success
64+
assert_output "Editing $NOTES_DIRECTORY/note.md"
65+
}
66+
67+
@test "Accepts names without .md to open" {
68+
touch $NOTES_DIRECTORY/note.md
69+
70+
run bash -c "$notes open note"
71+
72+
assert_success
73+
assert_output "Editing $NOTES_DIRECTORY/note.md"
5674
}

0 commit comments

Comments
 (0)