Skip to content

Commit fa925b0

Browse files
authored
Merge pull request #34 from primis/master
Added Ability to be extension agnostic
2 parents 87a96e7 + c680383 commit fa925b0

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ To get started with you'll want to set `$EDITOR` to your favourite text editor,
5151

5252
There are also more complex options available. You can set any configuration properties either in the environment, or in a config file (stored in `~/.config/notes/config`), with settings in config overriding those in your environment. This allows you to configure a different `$EDITOR` for notes to everything else, if you like. The config file is a good choice for more complex set ups, but probably not worth worrying about to start with. We've included an example config in this repo for you ([config.example](config.example)) that you can copy if you like.
5353

54-
The only other configuration property right now is `$QUICKNOTE_FORMAT`, which changes the way that quicknote filenames are generated. The string is formatted by passing it to the `date` command, and defaults to `quicknote-%Y-%m-%d`.
54+
### What are the configuration options?
55+
56+
* `QUICKNOTE_FORMAT` changes the way that quicknotes are generated. The string formatted using the `date` command.
57+
* `NOTES_EXT` changes the default extension that notes are saved with.
58+
* `NOTES_DIRECTORY` changes the directory in which notes are stored.
59+
* `EDITOR` can also be overriden here, for `notes` only.
60+
5561

5662
## How do I use it?
5763

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
@@ -99,7 +99,7 @@ generate_name() {
9999
local format_string="`date +$QUICKNOTE_FORMAT`"
100100
# Initial test has no append
101101
local resolved_name=$format_string
102-
while [[ -e "$notes_dir/$resolved_name.md" ]]
102+
while [[ -e "$notes_dir/$resolved_name.$NOTES_EXT" ]]
103103
do
104104
append_num=$[$append_num+1]
105105
resolved_name=$format_string.$append_num
@@ -113,7 +113,7 @@ new_note() {
113113
note_name="$(generate_name)"
114114
fi
115115
mkdir -p "$(dirname "$notes_dir/$note_name")"
116-
open_note "$note_name.md"
116+
open_note "$note_name.$NOTES_EXT"
117117
}
118118

119119
remove_note() {
@@ -126,8 +126,8 @@ remove_note() {
126126
local note_name="$*"
127127
local to_remove="$notes_dir/$note_name"
128128

129-
if [ -f "$notes_dir/$note_name.md" ]; then
130-
to_remove="$notes_dir/$note_name.md"
129+
if [ -f "$notes_dir/$note_name.$NOTES_EXT" ]; then
130+
to_remove="$notes_dir/$note_name.$NOTES_EXT"
131131
fi
132132
rm "${rm_args[@]}" "$to_remove"
133133
}
@@ -148,8 +148,8 @@ open_something() {
148148
open_note() {
149149
local note_path=$1
150150

151-
if [[ "$note_path" != *.md ]]; then
152-
note_path="$note_path.md"
151+
if [[ "$note_path" != *.$NOTES_EXT ]]; then
152+
note_path="$note_path.$NOTES_EXT"
153153
fi
154154
if [ ! -f "$note_path" ]; then
155155
note_path="$notes_dir/$note_path"

test/test-config.bats

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

0 commit comments

Comments
 (0)