-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit-integration.bashcomplete
135 lines (123 loc) · 2.42 KB
/
git-integration.bashcomplete
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!bash
__git_integration_branches () {
git for-each-ref --format='%(refname)' refs/insns/ 2>/dev/null |
sed -e 's!^refs/insns/!!'
}
__git_integration_prefixes () {
git for-each-ref --format='%(refname)' refs/remotes/ 2>/dev/null |
sed -e 's!^refs/remotes/!!' -e 's!/.*$!/!' |
sort | uniq
}
__git_integration_filter_prefix () {
if test -z "$branch_prefix"
then
cat
return
fi
local ref
while read -r ref
do
case "$ref" in
"$branch_prefix"*)
ref=${ref#$branch_prefix}
;;
refs/"$branch_prefix"*)
ref=${ref#refs/$branch_prefix}
;;
refs/tags/"$branch_prefix"*)
ref=${ref#refs/tags/$branch_prefix}
;;
refs/heads/"$branch_prefix"*)
ref=${ref#refs/heads/$branch_prefix}
;;
refs/remotes/"$branch_prefix"*)
ref=${ref#refs/remotes/$branch_prefix}
;;
*)
continue
;;
esac
printf '%s\n' "$ref"
done
}
__git_integration_options="\
--create
--add=
--edit
--cat
--rebuild
--no-rebuild
--status
--continue
--abort
--autocontinue
--no-autocontinue
--prefix=
"
_git_integration () {
# Disable default filename completion. Note that "compopt" is only
# available in Bash 4 and newer, so we check for existence before
# trying to use it.
type compopt >/dev/null 2>&1 && compopt +o default +o bashdefault
local branch_prefix=$(git config --get integration.prefix 2>/dev/null)
local i found_command=0 found_create=0 nargs=0
for ((i=0; i < ${cword}; i++)); do
case "$found_command,${words[i]}" in
1,--create)
found_create=1
;;
1,--prefix)
branch_prefix=${words[i+1]}
;;
1,--prefix=)
branch_prefix=${words[i]#--prefix=}
;;
?,-*)
:
;;
0,integration)
# This is the start of the arguments to
# "git integration".
found_command=1
;;
1,*)
((nargs++))
;;
esac
done
case "$cur" in
--add=*)
__gitcomp_nl "$(__git_refs | __git_integration_filter_prefix)" \
"" "${cur##--add=}"
return
;;
--prefix=*)
__gitcomp_nl "$(__git_integration_prefixes)" "" "${cur##--prefix=}"
return
;;
-*)
__gitcomp "$__git_integration_options"
return
;;
esac
if test "$prev" = "--add"
then
__gitcomp_nl "$(__git_refs | __git_integration_filter_prefix)"
return
fi
case $found_create,$nargs in
0,0)
__gitcomp_nl "$(__git_integration_branches)"
;;
?,1)
__gitcomp_nl "$(__git_heads | __git_integration_filter_prefix)"
;;
*)
COMPREPLY=()
return
esac
if test -z "$cur"
then
COMPREPLY+=($(compgen -W "$__git_integration_options"))
fi
}