Skip to content

Instantly share code, notes, and snippets.

@withakay
Created January 7, 2020 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save withakay/0c4a3e3fa085b32315ab2e90b27eb307 to your computer and use it in GitHub Desktop.
Save withakay/0c4a3e3fa085b32315ab2e90b27eb307 to your computer and use it in GitHub Desktop.
Doing. Log what you are doing to a text file with a timestamp in a markdown friendly manner
#!/usr/bin/env bash
# path to the 'doing' file, if this doesn't exist one will be created (see below)
DOING_FILE="~/Documents/doing.txt"
# the entry prefix, a tab and hyphen, so markdown parsers can render it
PREFIX=" -"
# date now as yyyy-MM-dd HH:mm - e.g. 2019-05-25 21:56
now=`date '+%F %H:%M'`
task="$@"
# A doing file needs to exist, if it doesn't one will be created
# It should start with 'Current:'
# followed by 3 blank lines
# and then 'Archived'
#
# Current:
#
#
#
# Archived:
if ! test -f $DOING_FILE; then
echo "$DOING_FILE does not exist!, creating" >&2
echo "Current:"> $DOING_FILE
echo "">> $DOING_FILE
echo "">> $DOING_FILE
echo "Archived:">> $DOING_FILE
echo "">> $DOING_FILE
fi
#
if [ "$task" == "" ]; then
echo "No task provided" >&2
else
# inserts text at line 3 of the doing file
sed -i '' '3s/^/'"$PREFIX"' '"$now"' | '"$task"'\'$'\n/' "$DOING_FILE"
echo "Added new task"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment