-
-
Save mortie/f4aba996d45d6535941e013f3e29ca8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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