Skip to content

Commit 8f37f78

Browse files
committed
Add support for explicit file extensions
1 parent fc584b3 commit 8f37f78

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ There are also more complex options available. You can set any configuration pro
105105

106106
Opens your `$EDITOR` of choice for a new note, with the given name. The name can include slashes, if you want to put your note in a subfolder. Leave out the name if you want one to be generated for you (e.g. `quicknote-2016-12-21.md` - format configurable with `$QUICKNOTE_FORMAT`). If you want to place a quicknote in a subfolder, use a trailing slash: `notes new subfolder/`. Shorthand alias also available with `notes n`.
107107

108+
If you do not supply an extension in `note-name`, it will be automatically appended with the default file extension (e.g. "newnote" will become "newnote.md"). However, if you include a one-to-four-letter file extension, notes will use that extension when creating the file (e.g. "newnote.tex" is created as "newnote.tex"; not "newnote.md", or "newnote.tex.md").
109+
108110
### `notes find <part-of-a-note-name>`
109111

110112
Searches note filenames and paths for the given string, and returns every single match. If no pattern is specified, this returns every single note. Shorthand alias also available with `notes f`.
@@ -129,6 +131,8 @@ Opens your notes folder in your default configured file explorer. Shorthand alia
129131

130132
Opens a given note in your `$EDITOR`. Name can be an absolute path, or a relative path in your notes (.md suffix optional). Shorthand alias also available with `notes o`.
131133

134+
If not file-suffix is given in `note-name`, the notes will attempt to open `note-name.md` (or whatever your default suffix is set to). However, if the note-name is given an suffix, the default suffix will not be appended (e.g. `notes open note-name.txt` will open `note-name.txt`; not `note-name.md` or `note-name.txt.md`).
135+
132136
### `notes mv <note-name> <destination>|<directory>`
133137

134138
Renames a given note to destination or moves the note to directory. Name can be an absolute path, or a relative path in your notes (.md suffix optional). Destination and directory have to be a relative path in your notes.

notes

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Version
4-
notes_version="0.5.3"
4+
notes_version="0.5.2"
55

66
# Default Date string before config
77
QUICKNOTE_FORMAT="quicknote-%Y-%m-%d"
@@ -173,10 +173,17 @@ handle_multiple_notes() {
173173
get_full_note_path() {
174174
local note_path=$1
175175

176-
if [[ "$note_path" != *.$NOTES_EXT ]]; then
177-
note_path="$note_path.$NOTES_EXT"
178-
fi
179-
if [ ! -f "$note_path" ]; then
176+
# first check if file exists
177+
if [ -f "$note_path" ]; then # note path given is good
178+
note_path="$note_path"
179+
elif [ -f "$notes_dir/$note_path" ]; then # exists
180+
note_path="$notes_dir/$note_path"
181+
elif echo "$note_path" | grep '[.][A-Za-z]\{1,4\}$' &>/dev/null; then # has a 1-4 letter extension
182+
note_path="$notes_dir/$note_path"
183+
else
184+
if [[ "$note_path" != *.$NOTES_EXT ]]; then
185+
note_path="$note_path.$NOTES_EXT"
186+
fi
180187
note_path="$notes_dir/$note_path"
181188
fi
182189

test/test-new.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,10 @@ notes="./notes"
7979
assert_success
8080
assert_exists "$NOTES_DIRECTORY/subfolder/quicknote-$today.md"
8181
}
82+
83+
@test "Should use explicitly named file extensions" {
84+
run $notes new explicit-ext.zzz
85+
86+
assert_success
87+
assert_exists "$NOTES_DIRECTORY/explicit-ext.zzz"
88+
}

test/test-open.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,12 @@ notes="./notes"
123123
assert_failure
124124
assert_output "Please set \$EDITOR to edit notes"
125125
}
126+
127+
@test "Accepts names with other file extensions to open" {
128+
touch $NOTES_DIRECTORY/test-note.txt
129+
130+
run bash -c "$notes open test-note.txt"
131+
132+
assert_success
133+
assert_output "Editing $NOTES_DIRECTORY/test-note.txt"
134+
}

0 commit comments

Comments
 (0)