-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-pair.sh
More file actions
55 lines (44 loc) · 1.16 KB
/
git-pair.sh
File metadata and controls
55 lines (44 loc) · 1.16 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
git-pair() {
if [ $# -eq 0 ]; then
echo "Usage: git-pair <alias>"
return 1
fi
local pair
local pair_alias="${1}"
local prev_message
local prev_message_without_co_authors
local co_authors
local new_co_author
local new_message
pair=$(
command grep "${pair_alias}" "${HOME}/.git-pair" \
| cut -d" " -f2-
)
prev_message=$(git log --format=%B --max-count=1)
prev_message_without_co_authors=$(
echo "$prev_message" \
| command grep -v "Co-authored-by: "
)
new_co_author="Co-authored-by: ${pair}"
co_authors=$(
echo "$prev_message" \
| command grep "Co-authored-by: " \
| cat - <(echo "$new_co_author") \
| LC_ALL=c sort -u
)
new_message="${prev_message_without_co_authors}"$'\n\n'"${co_authors}"
if [ "$new_message" != "$prev_message" ]; then
git commit --amend --message "$new_message" --quiet
echo "🍐'd with ${pair}"
else
echo "Already 🍐'd with ${pair}"
fi
}
_git_pair_completion() {
local options
local word="${2}"
options=$(awk '{print $1}' "${HOME}/.git-pair")
COMPREPLY=($(compgen -W "${options}" -- ${word}))
}
complete -F _git_pair_completion git-pair