Skip to content

Instantly share code, notes, and snippets.

@marek-saji
Last active May 29, 2020 08:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marek-saji/fd107bbd01d5436ca751effec335dae4 to your computer and use it in GitHub Desktop.
Save marek-saji/fd107bbd01d5436ca751effec335dae4 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Display a summary of what you’ve been working on since yesterday
# Copyright 2020 Marek Augustynowicz
# Licensed under ISC license <https://opensource.org/licenses/ISC>
#
# https://gist.github.com/marek-saji/fd107bbd01d5436ca751effec335dae4
# GistID: fd107bbd01d5436ca751effec335dae4
set -e
HEADER_FORMAT="\n\033[34m# %s\033[0m\n"
GIT_LOG_FORMAT="$( git config --get --default="%C(green)(%cd) %C(reset)%s%C(yellow)%d %C(red)%h%C(reset)" pretty.me )"
__ ()
{
# 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 config --get alias.mainbranch >/dev/null && git mainbranch || echo master )"
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
printf "\n\n\n\n\n"
md_cat="$( command -v pygmentize && echo " -l md" || echo cat )"
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" {} + \
| $md_cat
__ Commits
command git --no-pager -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 --no-pager 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 --no-pager -c color.ui=always log \
--since="$since" \
--until="$until" \
--author="$me" \
--format="$GIT_LOG_FORMAT" \
--date=format:'%F %H:%M' \
--date-order \
--first-parent \
--merges \
"$mainbranch@{u}"
__ Closed branches
command git -c color.ui=always branch -vv | grep gone | sed -s 's/\].*$/]/'
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