Browse Source

added debug functions/making templates better

master
Ben Savage 5 years ago
parent
commit
43a02138d4
  1. 28
      cl

28
cl

@ -1,6 +1,12 @@
#!/bin/bash #!/bin/bash
PROFILE='default' PROFILE='default'
function debug() {
if [ ${DEBUG:-0} ]; then
echo "$(date): $@"
fi
}
function help() { function help() {
cat << EOF cat << EOF
@ -120,12 +126,22 @@ function captains_log() {
# Create files if they don't exist # Create files if they don't exist
for i in YESTERDAY TODAY TOMORROW; do for i in YESTERDAY TODAY TOMORROW; do
if ! [ -f "$CLDIR/${!i}" ]; then if ! [ -f "$CLDIR/${!i}" ]; then
if [ -f "$CLDIR/template" ]; then # If there's a template and it's executable, execute it and output the result to the file,
echo -e "$(date "+%A %d %B %Y" -d ${!i})\n" > "$CLDIR/${!i}" # If it's not executable, replate {{DATE <date-compatible formate>}} with said date/formate
cat "$CLDIR/template" >> "$CLDIR/${!i}" # Otherwise do the boilerplate
fi 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}" 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 fi
fi
done done
@ -176,10 +192,12 @@ else
fi fi
while [ $1 ]; do while [ $1 ]; do
case $1 in 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;; review) review "$@"; exit;;
schedule) schedule "$@";exit;; schedule) schedule "$@";exit;;
help|--help|-h) help; exit;; help|--help|-h) help; exit;;
*) break;;
esac esac
done done

Loading…
Cancel
Save