diff --git a/cl b/cl index 69a4b93..b0b0cdb 100755 --- a/cl +++ b/cl @@ -1,6 +1,12 @@ #!/bin/bash PROFILE='default' +function debug() { + if [ ${DEBUG:-0} ]; then + echo "$(date): $@" + fi +} + function help() { cat << EOF @@ -120,11 +126,21 @@ function captains_log() { # Create files if they don't exist for i in YESTERDAY TODAY TOMORROW; do if ! [ -f "$CLDIR/${!i}" ]; then - if [ -f "$CLDIR/template" ]; then - echo -e "$(date "+%A %d %B %Y" -d ${!i})\n" > "$CLDIR/${!i}" - cat "$CLDIR/template" >> "$CLDIR/${!i}" + # If there's a template and it's executable, execute it and output the result to the file, + # 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 + 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 + debug "From static template with DATE_ARGS=$DATE_ARGS" + 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 - 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 done @@ -176,10 +192,12 @@ else fi while [ $1 ]; do case $1 in - -p|--profile) CLDIR="$HOME/.captains_log/$2"; shift 2;; + -p|--profile) CLDIR="$BASEDIR/$2"; shift 2;; + --debug) DEBUG=1; shift;; review) review "$@"; exit;; schedule) schedule "$@";exit;; help|--help|-h) help; exit;; + *) break;; esac done