Skip to content

Commit

Permalink
Add new command
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Nov 30, 2016
1 parent b1daef1 commit 4747168
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ find_notes() {
fi
}

new_note() {
$EDITOR $notes_dir/$1.md
}

usage() {
cat <<EOF
notes is a command line note taking tool.
Usage:
notes (new|n) <name> # Create a new note
notes find [pattern] # Search notes by filename and path
notes open # Open your notes directory
notes --help # Print this usage information
Expand All @@ -41,6 +46,9 @@ main() {
[ -z "$1" ] && echo "No command specified\n" && usage && exit 1

case "$1" in
"n" | "new" )
cmd="new_note"
;;
"find" )
cmd="find_notes"
;;
Expand Down
26 changes: 26 additions & 0 deletions test/test-new.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!./libs/bats/bin/bats

load 'libs/bats-support/load'
load 'libs/bats-assert/load'
load 'helpers'

# Set up a directory for our notes
TMP_DIRECTORY=$(mktemp -d)
export NOTES_DIRECTORY="$TMP_DIRECTORY"
export EDITOR=touch

notes="./notes"

@test "Should create a new note with the given name" {
run $notes new note

assert_success
assert_exists "$NOTES_DIRECTORY/note.md"
}

@test "Should create a new note with the given name, using 'n' alias" {
run $notes n note

assert_success
assert_exists "$NOTES_DIRECTORY/note.md"
}

0 comments on commit 4747168

Please sign in to comment.