Created
March 23, 2020 12:30
-
-
Save marek-saji/7bd3191417fcfd308710c48105230412 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 | |
# | |
# Display a summary of what you’ve been working on since yesterday | |
# | |
set -e | |
HEADER_FORMAT="\n\033[34m# %s\033[0m\n" | |
GIT_LOG_FORMAT="$( git config --get pretty.me --default="%C(green)(%cd) %C(reset)%s%C(yellow)%d %C(red)%h%C(reset)" )" | |
__ () | |
{ | |
# shellcheck disable=SC2059 | |
printf "$HEADER_FORMAT" "$*" | |
} | |
name="$( command git config --get user.name )" | |
email="$( command git config --get user.email )" | |
github_user="$( command git config --get github.user )" | |
me="$email\|$name\|$github_user@users.noreplay.git.com" # FIXME Escape regexp | |
printf "Hello," | |
printf " \033[4m%s\033[m" "$name" | |
printf " <\033[4m%s\033[m>" "$email" | |
if [ -n "$github_user" ] | |
then | |
printf " <https://github.com/\033[4m%s\033[m>" "$github_user" | |
fi | |
printf ".\n" | |
mainbranch="$( git mainbranch )" | |
remote="$( git remote | head -n1 )" # TODO get from $mainbranch | |
printf "Your base branch is \033[4m%s/%s\033[m.\n" "$remote" "$mainbranch" | |
if [ -n "$1" ] | |
then | |
since="$1" | |
else | |
since="$( | |
if [ "$( date +%u )" = "1" ] | |
then | |
echo 'last friday 00:00' | |
else | |
echo 'yesterday 00:00' | |
fi | |
)" | |
fi | |
if [ -n "$2" ] | |
then | |
until="$2" | |
else | |
until="now" | |
fi | |
printf "Showing things since \033[4m%s\033[m until \033[4m%s\033[m.\n" "$since" "$until" | |
git fetch | |
find ~ . -maxdepth 1 \ | |
\( -iname 'TODO' -or -iname 'TODO.md' -or -iname 'TODO.markdown' -or -iname 'TODO.txt' \) \ | |
-exec sh -c 'printf "$1" TODO; shift; head -n10000 "$@"' -- "$HEADER_FORMAT" {} + | |
__ Commits | |
command git -c color.ui=always log \ | |
--since="$since" \ | |
--until="$until" \ | |
--author="$me" \ | |
--format="$GIT_LOG_FORMAT" \ | |
--date=format:'%F %H:%M' \ | |
--date-order \ | |
--all \ | |
| awk 'prev && prev != $1 { print ""; } { prev=$1 } 1' | |
__ Active branches | |
shas="$( command git log --all --author="$me" --since="$since" --until="$until" --format="%H" )" | |
for sha in $shas | |
do | |
branches="$( | |
command git branch --all --color=never --contain "$sha" \ | |
| cut -b3- \ | |
| sed "s~^remotes/$remote/~~" | |
)" | |
if ! echo "$branches" | grep -qE "^(remotes/$remote/|)${mainbranch}$" | |
then | |
echo "$branches" | |
fi | |
done | grep -v '^$' | sort -u | |
__ Merged branches | |
command git -c color.ui=always log \ | |
--since="$since" \ | |
--until="$until" \ | |
--author="$me" \ | |
--format="$GIT_LOG_FORMAT" \ | |
--date=format:'%F %H:%M' \ | |
--date-order \ | |
--merges \ | |
"$mainbranch@{u}" | |
__ Closed branches | |
command git b | grep gone | |
if command -v gh >/dev/null | |
then | |
__ Pull requests | |
gh pr list --assignee=@me | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment