-
Notifications
You must be signed in to change notification settings - Fork 1
/
bashrc.git-series
141 lines (123 loc) · 2.4 KB
/
bashrc.git-series
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
136
137
138
139
140
141
#!bash
_git_series ()
{
local subcommands="create delete list propagate rename"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
# echo args=$@
# echo subcommands=$subcommands
# echo subcommand=$subcommand
# echo COMP_WORDS=${COMP_WORDS[*]}
# echo COMP_CWORD=$COMP_CWORD
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
create)
__git_series_create
return
;;
delete)
__git_series_delete
return
;;
list)
__git_series_list
return
;;
propagate)
__git_series_propagate
return
;;
rename)
__git_series_rename
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_series_create ()
{
local subcommands="help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
}
__git_series_delete ()
{
local hasF hasArg remainingWords=${COMP_WORDS[*]:3:$COMP_CWORD}
while getopts ":f" opt ${remainingWords[*]}; do
case $opt in
f)
hasF=y
;;
*)
echo OPT=$opt
;;
esac
if [ "${#remainingWords[@]}" -gt 0 ]; then
remainingWords=("${remainingWords[@]:$((OPTIND - 1))}")
fi
done
if [ -n "$remainingWords" ]; then
hasArg=y
fi
echo hasF=$hasF hasArg=$hasArg r=$remainingWords
__gitcomp "${hasF:+ -f} ${hasArg:-$(__git_series_list_series)}"
}
__git_series_release ()
{
local subcommands="list start finish track publish help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
finish)
__gitcomp "$(__git_series_list_branches 'release')"
return
;;
publish)
__gitcomp "$(comm -23 <(__git_series_list_branches 'release') <(__git_series_list_remote_branches 'release'))"
return
;;
track)
__gitcomp "$(comm -23 <(__git_series_list_remote_branches 'release') <(__git_series_list_branches 'release'))"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_series_hotfix ()
{
local subcommands="list start finish help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
finish)
__gitcomp "$(__git_series_list_branches 'hotfix')"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_series_list_series ()
{
git series list 2> /dev/null
}
__git_series_list_releases ()
{
git release list 2> /dev/null
}