1 | #----------------------------------------------------------- |
---|
2 | # Copyright Christian Arnault LAL-Orsay CNRS |
---|
3 | # arnault@lal.in2p3.fr |
---|
4 | # Written by Grigory Rybkin |
---|
5 | # See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
6 | #----------------------------------------------------------- |
---|
7 | |
---|
8 | shopt -s extglob |
---|
9 | |
---|
10 | _cmt_escape_compreply () |
---|
11 | { |
---|
12 | local i |
---|
13 | for ((i=0; i < ${#COMPREPLY[*]}; i++)); do |
---|
14 | [[ ! ${COMPREPLY[$i]} =~ ["${COMP_WORDBREAKS/$'\n'}"] ]] || \ |
---|
15 | COMPREPLY[$i]=$(sed "s,[${COMP_WORDBREAKS/$'\n'}],\\\\&,g" <<<"${COMPREPLY[$i]}") |
---|
16 | done |
---|
17 | } |
---|
18 | |
---|
19 | _cmt () |
---|
20 | { |
---|
21 | local commands=(broadcast build check check_files checkout co cleanup config create create_project expand filter help lock relocate remove run setup show system unlock version ${CVSROOT:+cvstags cvsbranches cvssubpackages cvssubprojects}) |
---|
22 | local with_subcommands=(build check expand remove show) |
---|
23 | local global_opts=(-disable_warnings -quiet -use= -pack= -version= -path= -f= -e= -tag= -tag_add= -tag_remove= -warnings -with_version_directory -without_version_directory -cleanup -no_cleanup -xml) |
---|
24 | local broadcast_opts=(-begin= -select= -exclude= -local -global -depth=) |
---|
25 | local build_subcmds=(CMT_pacman constituent_makefile constituents_makefile dependencies library_links make_setup msdev os9_makefile prototype readme tag_makefile temporary_name triggers win_makefile) |
---|
26 | local check_subcmds=(configuration files version) |
---|
27 | local show_subcmds=(action action_names action_value actions alias alias_names alias_value aliases all_tags applied_patterns author branches clients cmtpath_patterns constituent constituent_names constituents container cycles fragment fragments groups include_dirs language languages macro macro_names macro_value macros manager packages path pattern patterns projects project_author pwd set set_names set_value sets strategies tags use_paths uses versions) |
---|
28 | |
---|
29 | local cur _IFS="${IFS}" |
---|
30 | local i opts _COMPREPLY p mwds wordlist |
---|
31 | |
---|
32 | COMPREPLY=() |
---|
33 | cur=$2 |
---|
34 | |
---|
35 | local iself= icommand= command= isubcommand= subcommand= |
---|
36 | for ((i=0; i < COMP_CWORD; i++)); do |
---|
37 | if [ -z $iself ]; then |
---|
38 | [[ ${COMP_WORDS[i]} == $1 ]] && { iself=$i; } |
---|
39 | continue |
---|
40 | fi |
---|
41 | if [ -z $icommand ]; then |
---|
42 | # global options |
---|
43 | [[ ${COMP_WORDS[i]} == -* ]] && { continue; } |
---|
44 | # _IFS="${IFS}" |
---|
45 | IFS="|" |
---|
46 | commands_pattern="${commands[*]}" |
---|
47 | IFS="${_IFS}" |
---|
48 | if [[ ${COMP_WORDS[i]} == @(${commands_pattern}) ]]; then |
---|
49 | command=${COMP_WORDS[i]}; icommand=$i |
---|
50 | fi |
---|
51 | continue |
---|
52 | fi |
---|
53 | if [ -z $isubcommand ]; then |
---|
54 | # command options |
---|
55 | [[ ${COMP_WORDS[i]} == -* ]] && { continue; } |
---|
56 | # _IFS="${IFS}" |
---|
57 | IFS="|" |
---|
58 | with_subcommands_pattern="${with_subcommands[*]}" |
---|
59 | IFS="${_IFS}" |
---|
60 | if [[ $command == @(${with_subcommands_pattern}) ]]; then |
---|
61 | subcommand=${COMP_WORDS[i]}; isubcommand=$i |
---|
62 | fi |
---|
63 | continue |
---|
64 | fi |
---|
65 | done |
---|
66 | |
---|
67 | [ -z $iself ] && return 0 |
---|
68 | |
---|
69 | if [ -n "$isubcommand" ]; then |
---|
70 | case $command in |
---|
71 | build) |
---|
72 | case $subcommand in |
---|
73 | constituent_makefile|triggers) |
---|
74 | if (( isubcommand + 1 == COMP_CWORD )); then |
---|
75 | COMPREPLY=($(compgen -W "$(cmt -quiet show constituent_names)" -- "$cur")) |
---|
76 | fi |
---|
77 | ;; |
---|
78 | esac |
---|
79 | ;; |
---|
80 | check) |
---|
81 | case $subcommand in |
---|
82 | files) |
---|
83 | if (( isubcommand + 1 == COMP_CWORD || |
---|
84 | isubcommand + 2 == COMP_CWORD )); then |
---|
85 | return 0 |
---|
86 | IFS=$'\n' |
---|
87 | COMPREPLY=( $( compgen -f -- "${cur}" ) ) |
---|
88 | IFS="${_IFS}" |
---|
89 | _cmt_escape_compreply |
---|
90 | fi |
---|
91 | ;; |
---|
92 | esac |
---|
93 | ;; |
---|
94 | remove) |
---|
95 | case $subcommand in |
---|
96 | library_links) |
---|
97 | ;; |
---|
98 | *) |
---|
99 | if (( icommand + 3 == COMP_CWORD )); then |
---|
100 | return 0 |
---|
101 | IFS=$'\n' |
---|
102 | COMPREPLY=( $( compgen -f -- "${cur}" ) ) |
---|
103 | IFS="${_IFS}" |
---|
104 | _cmt_escape_compreply |
---|
105 | fi |
---|
106 | ;; |
---|
107 | esac |
---|
108 | ;; |
---|
109 | show) |
---|
110 | case $subcommand in |
---|
111 | constituent) |
---|
112 | if (( isubcommand + 1 == COMP_CWORD )); then |
---|
113 | COMPREPLY=($(compgen -W "$(cmt -quiet show constituent_names)" -- "$cur")) |
---|
114 | fi |
---|
115 | ;; |
---|
116 | fragment) |
---|
117 | if (( isubcommand + 1 == COMP_CWORD )); then |
---|
118 | COMPREPLY=($(compgen -W "$(cmt -quiet show fragments | sed 's#.*/fragments/##')" -- "$cur")) |
---|
119 | fi |
---|
120 | ;; |
---|
121 | action|action_value) |
---|
122 | if (( isubcommand + 1 == COMP_CWORD )); then |
---|
123 | COMPREPLY=($(compgen -W "$(cmt -quiet show action_names)" -- "$cur")) |
---|
124 | fi |
---|
125 | ;; |
---|
126 | alias|alias_value) |
---|
127 | if (( isubcommand + 1 == COMP_CWORD )); then |
---|
128 | COMPREPLY=($(compgen -W "$(cmt -quiet show alias_names)" -- "$cur")) |
---|
129 | fi |
---|
130 | ;; |
---|
131 | macro|macro_value) |
---|
132 | if (( isubcommand + 1 == COMP_CWORD )); then |
---|
133 | COMPREPLY=($(compgen -W "$(cmt -quiet show macro_names)" -- "$cur")) |
---|
134 | fi |
---|
135 | ;; |
---|
136 | pattern) |
---|
137 | if (( isubcommand + 1 == COMP_CWORD )); then |
---|
138 | COMPREPLY=($(compgen -W "$(cmt -quiet show pattern_names)" -- "$cur")) |
---|
139 | fi |
---|
140 | ;; |
---|
141 | set|set_value) |
---|
142 | if (( isubcommand + 1 == COMP_CWORD )); then |
---|
143 | COMPREPLY=($(compgen -W "$(cmt -quiet show set_names)" -- "$cur")) |
---|
144 | fi |
---|
145 | ;; |
---|
146 | esac |
---|
147 | ;; |
---|
148 | esac |
---|
149 | elif [ -n "$icommand" ]; then |
---|
150 | case $command in |
---|
151 | broadcast|run) |
---|
152 | IFS=$'\n' |
---|
153 | COMPREPLY=($(compgen -c -- "$cur")) |
---|
154 | IFS="${_IFS}" |
---|
155 | _cmt_escape_compreply |
---|
156 | [ "$command" = run ] && return 0 |
---|
157 | opts=1 |
---|
158 | for (( i=(icommand + 1); i < COMP_CWORD; i++ )); do |
---|
159 | [[ ${COMP_WORDS[i]} != -* ]] && { opts=; break; } |
---|
160 | done |
---|
161 | if [ -n "$opts" ]; then |
---|
162 | _COMPREPLY=($(compgen -W "${broadcast_opts[*]}" -- "$cur")) |
---|
163 | COMPREPLY=("${_COMPREPLY[@]}" "${COMPREPLY[@]}") |
---|
164 | fi |
---|
165 | ;; |
---|
166 | build) |
---|
167 | if (( icommand + 1 == COMP_CWORD )); then |
---|
168 | COMPREPLY=($(compgen -W "${build_subcmds[*]}" -- "$cur")) |
---|
169 | fi |
---|
170 | ;; |
---|
171 | check) |
---|
172 | if (( icommand + 1 == COMP_CWORD )); then |
---|
173 | COMPREPLY=($(compgen -W "${check_subcmds[*]}" -- "$cur")) |
---|
174 | fi |
---|
175 | ;; |
---|
176 | check_files) |
---|
177 | if (( icommand + 1 == COMP_CWORD || |
---|
178 | icommand + 2 == COMP_CWORD )); then |
---|
179 | return 0 |
---|
180 | IFS=$'\n' |
---|
181 | COMPREPLY=( $( compgen -f -- "${cur}" ) ) |
---|
182 | IFS="${_IFS}" |
---|
183 | _cmt_escape_compreply |
---|
184 | fi |
---|
185 | ;; |
---|
186 | create) |
---|
187 | if (( icommand + 3 == COMP_CWORD )); then |
---|
188 | return 0 |
---|
189 | COMPREPLY=( $( compgen -f -- "${cur}" ) ) |
---|
190 | fi |
---|
191 | ;; |
---|
192 | expand) |
---|
193 | if (( icommand + 1 == COMP_CWORD )); then |
---|
194 | COMPREPLY=($(compgen -W "model" -- "$cur")) |
---|
195 | fi |
---|
196 | ;; |
---|
197 | remove) |
---|
198 | if (( icommand + 3 == COMP_CWORD )); then |
---|
199 | return 0 |
---|
200 | COMPREPLY=( $( compgen -f -- "${cur}" ) ) |
---|
201 | elif (( icommand + 1 == COMP_CWORD )); then |
---|
202 | COMPREPLY=($(compgen -W "library_links" -- "$cur")) |
---|
203 | fi |
---|
204 | ;; |
---|
205 | show) |
---|
206 | if (( icommand + 1 == COMP_CWORD )); then |
---|
207 | COMPREPLY=($(compgen -W "${show_subcmds[*]}" -- "$cur")) |
---|
208 | fi |
---|
209 | ;; |
---|
210 | co|checkout) |
---|
211 | case $3 in |
---|
212 | -vd|-d) |
---|
213 | IFS=$'\n' |
---|
214 | COMPREPLY=( $( compgen -d -- "${cur}" ) ) |
---|
215 | IFS="${_IFS}" |
---|
216 | _cmt_escape_compreply |
---|
217 | ;; |
---|
218 | -requirements) |
---|
219 | return 0 |
---|
220 | COMPREPLY=( $( compgen -f -- "${cur}" ) ) |
---|
221 | ;; |
---|
222 | *) |
---|
223 | COMPREPLY=($(compgen -W "-l -R -r -C -i -vd -d -o -requirements -no_config -rs --help" -- "${cur}")) |
---|
224 | ;; |
---|
225 | # COMPREPLY=($(compgen -P "-" -W "l R r C i vd d o requirements no_config rs -help" -- ${cur#-})) |
---|
226 | esac |
---|
227 | ;; |
---|
228 | esac |
---|
229 | else |
---|
230 | if [[ ${COMP_LINE:0:${COMP_POINT}} =~ ^.*-((path|f)=|(use)=([^:]+:){2}) ]] ; then |
---|
231 | p=${COMP_LINE:${#BASH_REMATCH[0]}:$(($COMP_POINT - ${#BASH_REMATCH[0]}))} |
---|
232 | [ ${#p} -eq 0 ] && return 0 |
---|
233 | eval mwds=(${p}) 2>/dev/null || return 0 |
---|
234 | [ ${#mwds[*]} -le 1 ] && [ -n "${cur}" ] && return 0 |
---|
235 | fi |
---|
236 | if [ "$3" = make ]; then |
---|
237 | wordlist="$(cmt -quiet show constituent_names)" |
---|
238 | wordlist="${wordlist} $(cmt -quiet show groups)" |
---|
239 | wordlist="${wordlist} check all binclean help" |
---|
240 | COMPREPLY=($(compgen -W "${wordlist}" -- "$cur")) |
---|
241 | return 0 |
---|
242 | fi |
---|
243 | wordlist="${global_opts[*]} ${commands[*]}" |
---|
244 | COMPREPLY=($(compgen -W "${wordlist}" -- "$cur")) |
---|
245 | fi |
---|
246 | |
---|
247 | return 0 |
---|
248 | } |
---|
249 | |
---|
250 | complete -o default -F _cmt cmt |
---|