Skip to content

Instantly share code, notes, and snippets.

@mortie
Created July 25, 2017 06:45
Show Gist options
  • Save mortie/f4aba996d45d6535941e013f3e29ca8c to your computer and use it in GitHub Desktop.
Save mortie/f4aba996d45d6535941e013f3e29ca8c to your computer and use it in GitHub Desktop.
#!/bin/sh
f="$(dirname $0)/log.txt"
if [ "$1" = "time" ]; then
last="$(cat "$f" | grep "# " | tail -n 1 | sed 's/^.*: //' | cut -d '-' -f 1)"
last=$(date +%s -d "$last")
now=$(date +%s)
diff=$(($now - $last))
printf "%02dh %02dm %02ds\n" $(($diff / 3600)) $(($diff % 3600 / 60)) $(($diff % 60))
exit 0
fi
d="# $(date +"%Y-%m-%d (%A)")"
if ! cat "$f" | grep --fixed-strings "$d" >/dev/null 2>/dev/null; then
start="$(date +"%H:%M")"
end="$(date --date 8hours +"%H:%M")"
str="$d: $start-$end"
echo >> "$f"
echo "$str" >> "$f"
echo "$str"
else
$EDITOR "$f"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment