Skip to content

Instantly share code, notes, and snippets.

@maelvls
Last active June 14, 2021 08:13
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 maelvls/e205d35ace6a68e6683c3ca1dff1a581 to your computer and use it in GitHub Desktop.
Save maelvls/e205d35ace6a68e6683c3ca1dff1a581 to your computer and use it in GitHub Desktop.
whatdidido, the CLI for finding out what I was doing on a given day across all my git repos. I often use this to help me fill my Clockify entries (https://maelvls.dev/clockidup/)
#! /bin/bash
help() {
cat <<EOF
I often need to remember what I was doing on a certain day. So I built
this tool to help me find that out. Note that it requires GNU date.
To configure which repositories are looked into, edit the EOF block at
the end of the source of this tool.
USAGE:
whatdidido yesterday
whatdidido "last friday"
whatdidido "May 6, 2021"
whatdidido "2021-05-06"
The date formats are the ones GNU date -d accepts. The output looks
like this:
cert-manager-website 19:39 certificaterequest: more doc around approval api
cert-manager 18:54 add a .golangci.yml so that we can all have same behavior
EOF
}
set -ueo pipefail
day_raw=
while [ $# -gt 0 ]; do
case $1 in
help)
help
exit 0
;;
*)
day_raw="$1"
;;
esac
shift
done
if test -z "$day_raw"; then
echo "you need to give a day, e.g., 'yesterday' or 'last friday'" >&2
exit 1
fi
if ! day=$(date -d "$day_raw" +"%Y-%m-%d"); then
echo "could not parse day '$day_raw'" >&2
exit 1
fi
while read -r project; do
if ! test -d "$project/.git"; then
continue
fi
# At first, I was using git log --before=... --after=... but it uses
# the committer date, and since I rebase quite a lot, the committer
# date does not reflect the day I actually worked on this commit.
#
# The workaround is to filter using awk:
# https://stackoverflow.com/questions/37311494
git -C "$project" log --author="$(git config user.email)" --date=format:"%Y-%m-%d %H:%M" --date-order \
--format=format:"%ad %x08 %C(yellow)$(basename "$project")%Creset %s" --color \
--all \
$(git -C "$project" reflog show --format="%h" 2>/dev/null) \
| awk '$1 >= "'$day'" && $1 <= "'$day'"'
done \
<<EOF
$HOME/code/cert-manager-website
$HOME/code/cert-manager/
$(ls -d ~/code/jetstack/*/)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment