-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-polite
executable file
·35 lines (28 loc) · 1.07 KB
/
git-polite
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash
findconvicts() {
echo "Choose your co-authors:"
usualsuspects=~/.gitco_suspects
suspects="$PWD/.suspects"
convicts=$(cat $usualsuspects "$suspects" <(git shortlog -sne --all | cut -f 2 | grep -v "$(git config user.name) <$(git config user.email)>" | head -n 5) 2>/dev/null | grep "\S" | sort -dut\< -k2,2 | sort | gum choose --no-limit | sed 's/^/Co-authored-by: /')
}
# Check provided arguments
while getopts "am:" flag; do
case "$flag" in
a) git add --all ;;
m) summary="$OPTARG" ;;
*) exit 0 ;;
esac
done
# If no summary has been provied assume interactive mode
if [ -z "$summary" ]; then
summary=$(gum input --prompt "Summary > " --placeholder "Summary of this change")
echo "Description of changes (CTRL+D to finish)"
description=$(gum write --placeholder "Details of this change (CTRL+D to finish)" --show-line-numbers)
fi
# Always suggest adding co-authors
findconvicts
# Confirm the commit
gum confirm "Commit the changes?" && git commit -m "$summary
$description
$convicts"
exit 0