Skip to content

Commit fb1b621

Browse files
authored
Merge pull request #28 from primis/master
Add Configuration File Support
2 parents 3e40b1c + 27c4902 commit fb1b621

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ curl https://cdn.rawgit.com/pimterry/notes/v0.1.2/notes > /usr/local/bin/notes &
2929

3030
By default your notes live in ~/notes, but you can change that to anywhere you like by setting the `$NOTES_DIRECTORY` environmental variable.
3131

32+
## How do I configure this?
33+
34+
You can set the configuration by creating a file at "~/.config/notes/config". We've included an example for you (config.example) that you can copy.
35+
3236
### Bash completion
3337

3438
If you want bash autocompletion copy the completion script into the bash completion directory. The bash completion directory is `/usr/share/bash-completion/completions/` on a typical debian jessie install, you can you can get the bash completion directory by running the following command:

config.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This is an example configuration file for notes
2+
# To use it, copy to ~/.config/notes/config
3+
# This config is case sensitive
4+
5+
# Set the editor that notes are opened with
6+
EDITOR=nano

notes

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

3+
# Look for configuration file at ~/.config/notes/config and use it
4+
if [ -f ~/.config/notes/config ]; then
5+
. ~/.config/notes/config
6+
fi
7+
38
configured_dir=${NOTES_DIRECTORY%/} # Remove trailing slashes
49
notes_dir="${configured_dir:-$HOME/notes}"
510
escaped_notes_dir="$(printf "$notes_dir" | sed -e 's/[]\/$*.^|[]/\\&/g')"

test/helpers.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ refute_exists() {
88

99
setupNotesEnv() {
1010
export NOTES_DIRECTORY="$(mktemp -d)"
11+
export NOTES_HOME="$(mktemp -d)"
12+
export HOME=$NOTES_HOME
1113
}
1214

1315
teardownNotesEnv() {
1416
if [ $BATS_TEST_COMPLETED ]; then
1517
rm -rf $NOTES_DIRECTORY
18+
rm -rf $NOTES_HOME
1619
else
1720
echo "** Did not delete $NOTES_DIRECTORY, as test failed **"
1821
fi

test/test-config.bats

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!./libs/bats/bin/bats
2+
3+
load 'libs/bats-support/load'
4+
load 'libs/bats-assert/load'
5+
load 'helpers'
6+
7+
setup() {
8+
setupNotesEnv
9+
}
10+
11+
teardown() {
12+
teardownNotesEnv
13+
}
14+
15+
notes="./notes"
16+
17+
@test "Configuration should override EDITOR" {
18+
mkdir -p $HOME/.config/notes
19+
echo "EDITOR=echo" > $HOME/.config/notes/config
20+
run $notes new test
21+
22+
assert_success
23+
assert_line "$NOTES_DIRECTORY/test.md"
24+
}

0 commit comments

Comments
 (0)