From 658ba0031ab9fe102c49fc6fc354add5763a267f Mon Sep 17 00:00:00 2001 From: Anand Patil Date: Mon, 24 Sep 2018 14:12:03 -0400 Subject: [PATCH 1/2] Added abiility to create quicknote in subfolder --- README.md | 2 +- notes | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6466d5..d88af8b 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ There are also more complex options available. You can set any configuration pro ### `notes new ` -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`). Shorthand alias also available with `notes n`. +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`. ### `notes find ` diff --git a/notes b/notes index 65cdf14..b71b205 100755 --- a/notes +++ b/notes @@ -118,6 +118,11 @@ new_note() { if [[ $note_name == "" ]]; then note_name="$(generate_name)" fi + + if echo "$note_name" | grep "/$" &> /dev/null; then + note_name="${note_name}/$(generate_name)" + fi + mkdir -p "$(dirname "$notes_dir/$note_name")" open_note "$note_name" From ce40ac0a576110dbc0d4878b4e0808e4509c962d Mon Sep 17 00:00:00 2001 From: Anand Patil Date: Mon, 24 Sep 2018 14:14:16 -0400 Subject: [PATCH 2/2] Added test --- test/test-new.bats | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test-new.bats b/test/test-new.bats index dac96b9..5f638ba 100755 --- a/test/test-new.bats +++ b/test/test-new.bats @@ -73,3 +73,11 @@ notes="./notes" assert_success assert_exists "$NOTES_DIRECTORY/notes with spaces/note.md" } + +@test "Should create quicknote in a subfolder" { + today=`date "+%Y-%m-%d"` + run $notes new subfolder/ + + assert_success + assert_exists "$NOTES_DIRECTORY/subfolder/quicknote-$today.md" +}