Skip to content

Instantly share code, notes, and snippets.

@inverse
Created May 9, 2023 13:53
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 inverse/1214cb5f8f5ded2600601f51359602ee to your computer and use it in GitHub Desktop.
Save inverse/1214cb5f8f5ded2600601f51359602ee to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -uf -o pipefail
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
echo "Not in a git repository"
exit 1
fi
TEMPLATE_PATH="$(git rev-parse --show-toplevel)/.git/template"
git config commit.template $TEMPLATE_PATH
if [[ -e "$HOME/.colleagues.txt" ]] ; then
COLLEAGUES="$(cat $HOME/.colleagues.txt)"
else
COLLEAGUES=""
fi
TRAILERS=""
while true ; do
pick="$(echo -e "$COLLEAGUES\n$(git shortlog -e -s | cut -f2)" | uniq | fzy)"
if [[ "$pick" != "" ]]; then
TRAILERS+="Co-authored-by: $pick\n"
echo "Added co-author: $pick"
else
break
fi
done
if [[ "$TRAILERS" != "" ]] ; then
echo -e "\n" > $TEMPLATE_PATH
echo -e "$TRAILERS" >> $TEMPLATE_PATH
echo "🧑‍💻 Pairing mode enabled. Run 'git unpair' to end session."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment