From b0b88986252feba1be9aa9c49e34bd93acd3960b Mon Sep 17 00:00:00 2001 From: Ben Savage Date: Mon, 5 Jul 2021 18:18:25 +1000 Subject: [PATCH] fixed debug/template code --- cl | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/cl b/cl index b0b0cdb..53e3da1 100755 --- a/cl +++ b/cl @@ -2,6 +2,7 @@ PROFILE='default' function debug() { + echo $DEBUG if [ ${DEBUG:-0} ]; then echo "$(date): $@" fi @@ -33,7 +34,10 @@ $0 - Captain's log Run with "review" ($0 review), and you will get a rundown of complete and incomplete tasks for the week. Optionally, supply with date-compatible strings as "$0 review [end] to use a range, end defaults to yesterday A task is considered complete if it matches the regex /^ \*/ and incomplete matching /* \-/ - events are also printed, assuming ! below + I've also implemented /^ ~/, implying a continuing task (as opposed to - which I'm sort of considering "not only incomplete, but barely progressed/attempted"). + For the purposes of review, ~ counts as Completed. + I'm hoping to capture which tasks are is under-estimated. + Events are also printed, assuming ! below Notes are generally ignored, but can be started with "^ #", "^ ;", or "^ !" for future functionality This will evolve with use, but generally (and in order of importance) @@ -65,9 +69,9 @@ function review() { - for j in '*' '-' '!'; do + for j in '*|~' '-' '!' ; do case $j in - \*) echo "Completed Tasks:";; + \*|\~) echo "Completed Tasks:";; \-) echo "Incomplete Tasks:";; \!) echo "Events:";; esac @@ -117,12 +121,21 @@ function captains_log() { TODAY=$(date +%F) TOMORROW=$(date +%F -d "+${modT:-1} day") - + if [ ${GIT:-1} ] && [ -f "$CLDIR/.git" ]; then + GIT=1 + else + GIT=0 + fi if ! [ -d "$CLDIR" ]; then mkdir "$CLDIR" fi + if [ $GIT ]; then + git -C "$CLDIR" pull & + fi + + # Create files if they don't exist for i in YESTERDAY TODAY TOMORROW; do if ! [ -f "$CLDIR/${!i}" ]; then @@ -130,14 +143,14 @@ function captains_log() { # If it's not executable, replate {{DATE }} with said date/formate # Otherwise do the boilerplate debug "File $i doesn't exist, creating it" - if [ -x "$CLDIR/template"]; then + if [ -x "$CLDIR/template" ]; then debug "From executable template" "$CLDIR/template" > $CLDIR/${!i} elif [ -f "$CLDIR/template" ]; then DATE_ARGS="$(grep '{{DATE[^}]*}}' "$CLDIR/template"|tr -d {}|cut -d' ' -f2-)" - if [ "$DATE_ARGS"=='' ]; then DATE_ARGS='%A %d %B %Y'; fi + if [ "$DATE_ARGS" == '' ]; then DATE_ARGS='%A %d %B %Y'; fi debug "From static template with DATE_ARGS=$DATE_ARGS" - sed 's/{{DATE[^}]*}}/$(date "+$DATE_ARGS" -d ${!i})/g' $CLDIR/template > $CLDIR/${!i} + sed "s/{{DATE[^}]*}}/$(date "+$DATE_ARGS" -d ${!i})/g" $CLDIR/template > $CLDIR/${!i} else echo -e "$(date "+%A %d %B %Y" -d ${!i})\nWhat do you want to accomplish today?\n\nWhat are your notes for today?\n\nWhat do you need to follow up tomorrow?\n" > "$CLDIR/${!i}" fi @@ -157,7 +170,7 @@ function captains_log() { if ! grep -qE "^Scheduled to Review today:" "$CLDIR/${!i}"; then echo "Scheduled to Review today:" >> "$CLDIR/${!i}" fi - if ! grep -qE "^ - $TASK" "$CLDIR/${!i}";then + if ! grep -qE "^ . $TASK" "$CLDIR/${!i}";then echo " - $TASK" >> "$CLDIR/${!i}" fi @@ -181,6 +194,14 @@ function captains_log() { vi -O $CLDIR/{$YESTERDAY,$TODAY,$TOMORROW} + + if [ $GIT ]; then + if [ $( git -C "$CLDIR" status -s |wc -l) -ne 0 ]; then + git -C "$CLDIR" add -A + git -C "$CLDIR" commit -m "Audo-Commit by $(basename $0)" + git -C "$CLDIR" push + fi + fi } BASEDIR="$HOME/.captains_log" @@ -193,6 +214,7 @@ fi while [ $1 ]; do case $1 in -p|--profile) CLDIR="$BASEDIR/$2"; shift 2;; + --no-git) GIT=0;shift;; --debug) DEBUG=1; shift;; review) review "$@"; exit;; schedule) schedule "$@";exit;;