Skip to content

Instantly share code, notes, and snippets.

@kousu
Last active August 19, 2017 19:26
Show Gist options
  • Save kousu/463c3d2426e0e0e1791ebeeac371c241 to your computer and use it in GitHub Desktop.
Save kousu/463c3d2426e0e0e1791ebeeac371c241 to your computer and use it in GitHub Desktop.
Handy personal journal script
#!/bin/sh
# journal
#
# Usage: journal [date]
#
# Spawn your plain-text $EDITOR open to your diary.
# Journal files are arranged in a simple tree hiearchy by date under ~/Journal/.
# If date is given, it is a date string as understood by GNU date;
# you can say for example,
# journal yesterday
# journal "2 days ago" # to open 2 days ago
# journal "1 week" # to open a week in the future
if [ ! -z $XAUTHORITY ]; then
EDITOR="leafpad --jump=-1" # HACK: make sure we go to the end of the line for the journal
fi
DAY=${1:-today}
JOURNAL=~/Journal/`date -d "$DAY" +%Y`/`date -d "$DAY" +%m`/`date -d "$DAY" +%d`.txt
if [ ! -f $JOURNAL ]; then
cat > $JOURNAL <<EOF
Journal for $(date -d "$DAY" +"%A %B %d, %Y")
------------------------------------------
EOF
fi
${EDITOR:-vi} $JOURNAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment