Skip to content

Commit 0503945

Browse files
committed
Made notes extension-agnostic
1 parent 5b7bdca commit 0503945

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,19 @@ You'll need to open a new shell for this to take effect.
4949

5050
You can set your favourite text editor and your notes directory by setting the `$EDITOR` and `$NOTES_DIRECTORY` environmental variables.
5151

52-
You can also set `$QUICKNOTE_FORMAT` to change the way that quicknotes are generated. The string formatted using the `date` command.
5352

5453
Most users shouldn't need to do any more than that. If you're doing anything more complicated though, you can configure `notes` config directly in "~/.config/notes/config", including EDITOR and NOTES_DIRECTORY. We've included an example in this repo for you ([config.example](config.example)) that you can copy. Any values set in the config file override values in environment variables.
5554

5655
Right now this mainly exists in case you want to use a different `EDITOR` for notes than the one you have set in your environment generally, but this is where all other config will be living in future.
5756

57+
### What are the configuration options?
58+
59+
* `QUICKNOTE_FORMAT` changes the way that quicknotes are generated. The string formatted using the `date` command.
60+
* `NOTES_EXT` changes the default extension that notes are saved with.
61+
* `NOTES_DIRECTORY` changes the directory in which notes are stored.
62+
* `EDITOR` can also be overriden here, for `notes` only.
63+
64+
5865
## How do I use it?
5966

6067
### `notes new <note-name>`

config.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ EDITOR=nano
77

88
# Change the quicknote format to get rid of the word "quicknote"
99
QUICKNOTE_FORMAT="%Y-%m-%d"
10+
11+
# Set extension to plain txt instead of markdown
12+
NOTES_EXT="txt"

notes

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Default Date string before config
44
QUICKNOTE_FORMAT="quicknote-%Y-%m-%d"
5-
5+
NOTES_EXT="md"
66
# Look for configuration file at ~/.config/notes/config and use it
77
if [ -f ~/.config/notes/config ]; then
88
. ~/.config/notes/config
@@ -76,7 +76,7 @@ generate_name() {
7676
local format_string="`date +$QUICKNOTE_FORMAT`"
7777
# Initial test has no append
7878
resolved_name=$format_string
79-
while [[ -e "$notes_dir/$resolved_name.md" ]]
79+
while [[ -e "$notes_dir/$resolved_name.$NOTES_EXT" ]]
8080
do
8181
append_num=$[$append_num+1]
8282
resolved_name=$format_string.$append_num
@@ -90,7 +90,7 @@ new_note() {
9090
note_name=$resolved_name
9191
fi
9292
mkdir -p "$(dirname "$notes_dir/$note_name")"
93-
open_note "$note_name.md"
93+
open_note "$note_name.$NOTES_EXT"
9494
}
9595

9696
remove_note() {
@@ -103,8 +103,8 @@ remove_note() {
103103
local note_name="$*"
104104
local to_remove="$notes_dir/$note_name"
105105

106-
if [ -f "$notes_dir/$note_name.md" ]; then
107-
to_remove="$notes_dir/$note_name.md"
106+
if [ -f "$notes_dir/$note_name.$NOTES_EXT" ]; then
107+
to_remove="$notes_dir/$note_name.$NOTES_EXT"
108108
fi
109109
rm "${rm_args[@]}" "$to_remove"
110110
}
@@ -125,8 +125,8 @@ open_something() {
125125
open_note() {
126126
local note_path=$1
127127

128-
if [[ "$note_path" != *.md ]]; then
129-
note_path="$note_path.md"
128+
if [[ "$note_path" != *.$NOTES_EXT ]]; then
129+
note_path="$note_path.$NOTES_EXT"
130130
fi
131131
if [ ! -f "$note_path" ]; then
132132
note_path="$notes_dir/$note_path"

test/test-config.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,12 @@ notes="./notes"
3232
assert_success
3333
assert_line "$NOTES_DIRECTORY/test.md"
3434
}
35+
36+
@test "Configuration should override file extension" {
37+
mkdir -p $HOME/.config/notes
38+
echo "NOTES_EXT=txt" > $HOME/.config/notes/config
39+
run $notes new test
40+
41+
assert_success
42+
assert_exists "$NOTES_DIRECTORY/test.txt"
43+
}

0 commit comments

Comments
 (0)