From 7aaa3947823c4577f037c759506d7e2817cc976f Mon Sep 17 00:00:00 2001 From: Alexander Bernauer Date: Mon, 26 Dec 2016 08:37:57 +0100 Subject: [PATCH 1/6] Support cancelling of editing of a task note. When having second thoughts while editing a task note, it is convenient to just cancel the edit as opposed to leaving the file unchanged. The difference is that cancel will not cause an additional annotation on the task. --- tasknote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasknote b/tasknote index a041861..63a913c 100755 --- a/tasknote +++ b/tasknote @@ -98,7 +98,7 @@ if [ $# -gt 1 ]; then fi #create/edit $file with editor -$SHELL -c "$EDITOR $file" +$SHELL -c "$EDITOR $file" || exit 1 # Create a note message representing the first line of # the edited note file. From 444daef80713f6d47394650bae09fc6d1eaaa277 Mon Sep 17 00:00:00 2001 From: Alexander Bernauer Date: Mon, 26 Dec 2016 09:24:33 +0100 Subject: [PATCH 2/6] Remove superfluous semicolon --- tasknote | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasknote b/tasknote index 63a913c..015be9c 100755 --- a/tasknote +++ b/tasknote @@ -53,10 +53,10 @@ if [ ! -d $FOLDER ]; then read answer if [ $answer == "y" ]; then echo "Creating '$FOLDER'." - mkdir -p $FOLDER; + mkdir -p $FOLDER else echo "Did NOT create $FOLDER. Exiting." - exit 1; + exit 1 fi fi From f829fb000c518cca1ed6a409560f983e7c0f46a6 Mon Sep 17 00:00:00 2001 From: Alexander Bernauer Date: Mon, 26 Dec 2016 09:27:38 +0100 Subject: [PATCH 3/6] Consistently quote paths --- tasknote | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tasknote b/tasknote index 015be9c..ba896cc 100755 --- a/tasknote +++ b/tasknote @@ -47,15 +47,15 @@ VIEWER=cat FOLDER="~/Dropbox/tasks/notes/" # Check for existence of $FOLDER -if [ ! -d $FOLDER ]; then +if [ ! -d "$FOLDER" ]; then echo "Notes folder '$FOLDER' does not exist." echo -n "Shall I create it (y/n)? " read answer if [ $answer == "y" ]; then echo "Creating '$FOLDER'." - mkdir -p $FOLDER + mkdir -p "$FOLDER" else - echo "Did NOT create $FOLDER. Exiting." + echo "Did NOT create '$FOLDER'. Exiting." exit 1 fi fi @@ -78,19 +78,19 @@ fi uuid=`$TASKBIN $1 uuids` # build full path & file name to store notes in -folder=`echo $FOLDER | sed "s|^~|$HOME|"` +folder=`echo "$FOLDER" | sed "s|^~|$HOME|"` file="$folder$uuid$EXT" # determine if notes file already exists fileexists=0 -if [ -f $file ]; then +if [ -f "$file" ]; then fileexists=1 fi # Display note if requested and exit if [ $# -gt 1 ]; then if [ $fileexists = 1 ]; then - $SHELL -c "$VIEWER $file" + $SHELL -c "$VIEWER \"$file\"" else echo "File not found" fi @@ -98,12 +98,12 @@ if [ $# -gt 1 ]; then fi #create/edit $file with editor -$SHELL -c "$EDITOR $file" || exit 1 +$SHELL -c "$EDITOR \"$file\"" || exit 1 # Create a note message representing the first line of # the edited note file. -if [ -f $file ]; then - NOTEMSG="[tasknote] `head -1 $file`" +if [ -f "$file" ]; then + NOTEMSG="[tasknote] "`head -1 "$file"` # remove any previous annotation - we want only a single # tasknote annotation. Detection works through the # [tasknote] annotation prefix From 94b69f7962aa3602c5d872662403f51d6f3df073 Mon Sep 17 00:00:00 2001 From: Alexander Bernauer Date: Mon, 26 Dec 2016 10:09:45 +0100 Subject: [PATCH 4/6] Keep config independent from path delimiters Like this config can focus on what it is actually configuring, leaving the plumbing to the tooling. --- tasknote | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasknote b/tasknote index ba896cc..80e53cc 100755 --- a/tasknote +++ b/tasknote @@ -44,7 +44,7 @@ VIEWER=cat # FOLDER to store notes in. Must already exist. # If you sync tasks, FOLDER should be a location that syncs and is available to # other computers, i.e. ~/dropbox/tasknotes -FOLDER="~/Dropbox/tasks/notes/" +FOLDER="~/Dropbox/tasks/notes" # Check for existence of $FOLDER if [ ! -d "$FOLDER" ]; then @@ -61,7 +61,7 @@ if [ ! -d "$FOLDER" ]; then fi # Preferred extension for tasknotes -EXT=".txt" +EXT="txt" # Message that gets annotated to the task to indicate that notes exist NOTEMSG="See Notes File" @@ -79,7 +79,7 @@ uuid=`$TASKBIN $1 uuids` # build full path & file name to store notes in folder=`echo "$FOLDER" | sed "s|^~|$HOME|"` -file="$folder$uuid$EXT" +file="$folder/$uuid.$EXT" # determine if notes file already exists fileexists=0 From 0fdf5095c3f458a9b51713ee2aa9cd5384fc08d4 Mon Sep 17 00:00:00 2001 From: Alexander Bernauer Date: Mon, 26 Dec 2016 10:18:04 +0100 Subject: [PATCH 5/6] Use task's data location as base path for notes --- tasknote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasknote b/tasknote index 80e53cc..553538d 100755 --- a/tasknote +++ b/tasknote @@ -44,7 +44,7 @@ VIEWER=cat # FOLDER to store notes in. Must already exist. # If you sync tasks, FOLDER should be a location that syncs and is available to # other computers, i.e. ~/dropbox/tasknotes -FOLDER="~/Dropbox/tasks/notes" +FOLDER=`task _show | awk -F= '/data\.location/ {print $2}'`/notes # Check for existence of $FOLDER if [ ! -d "$FOLDER" ]; then From 5f750ccfbfe79dc0e5a6ec92cced19e60342317b Mon Sep 17 00:00:00 2001 From: Alexander Bernauer Date: Mon, 26 Dec 2016 10:21:55 +0100 Subject: [PATCH 6/6] Suppport single quotes in first line of note file. Bash quoting and escaping is a beast. --- tasknote | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasknote b/tasknote index 553538d..ace8f7f 100755 --- a/tasknote +++ b/tasknote @@ -103,12 +103,13 @@ $SHELL -c "$EDITOR \"$file\"" || exit 1 # Create a note message representing the first line of # the edited note file. if [ -f "$file" ]; then - NOTEMSG="[tasknote] "`head -1 "$file"` + ESCAPED=`sed -e "s/'/\\\'/g" "$file" | head -1` + NOTEMSG="[tasknote] $ESCAPED" # remove any previous annotation - we want only a single # tasknote annotation. Detection works through the # [tasknote] annotation prefix $SHELL -c "$TASKBIN $* denotate \"[tasknote]\"" - $SHELL -c "$TASKBIN $* annotate '$NOTEMSG'" + $SHELL -c "$TASKBIN $* annotate \"$NOTEMSG\"" fi exit 0