source: CMT/HEAD/src/setup.bash @ 586

Last change on this file since 586 was 586, checked in by rybkin, 13 years ago

See C.L. 464

File size: 7.3 KB
Line 
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
8shopt -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 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                    macro|macro_value)
127                        if (( isubcommand + 1 == COMP_CWORD )); then
128                            COMPREPLY=($(compgen -W "$(cmt -quiet show macro_names)" -- "$cur"))
129                        fi
130                        ;;
131                    pattern)
132                        if (( isubcommand + 1 == COMP_CWORD )); then
133                            COMPREPLY=($(compgen -W "$(cmt -quiet show pattern_names)" -- "$cur"))
134                        fi
135                        ;;
136                    set|set_value)
137                        if (( isubcommand + 1 == COMP_CWORD )); then
138                            COMPREPLY=($(compgen -W "$(cmt -quiet show set_names)" -- "$cur"))
139                        fi
140                        ;;
141                esac
142                ;;
143        esac
144    elif [ -n "$icommand" ]; then
145        case $command in
146            broadcast|run)
147                IFS=$'\n'
148                COMPREPLY=($(compgen -c -- "$cur"))
149                IFS="${_IFS}"
150                _cmt_escape_compreply
151                [ "$command" = run ] && return 0
152                opts=1
153                for (( i=(icommand + 1); i < COMP_CWORD; i++ )); do
154                    [[ ${COMP_WORDS[i]} != -* ]] && { opts=; break; }
155                done
156                if [ -n "$opts" ]; then
157                    _COMPREPLY=($(compgen -W "${broadcast_opts[*]}" -- "$cur"))
158                    COMPREPLY=("${_COMPREPLY[@]}" "${COMPREPLY[@]}")
159                fi
160                ;;
161            build)
162                if (( icommand + 1 == COMP_CWORD )); then
163                    COMPREPLY=($(compgen -W "${build_subcmds[*]}" -- "$cur"))
164                fi
165                ;;
166            check)
167                if (( icommand + 1 == COMP_CWORD )); then
168                    COMPREPLY=($(compgen -W "${check_subcmds[*]}" -- "$cur"))
169                fi
170                ;;
171            check_files)
172                if (( icommand + 1 == COMP_CWORD ||
173                            icommand + 2 == COMP_CWORD )); then
174                    return 0
175                    IFS=$'\n'
176                    COMPREPLY=( $( compgen -f -- "${cur}" ) )
177                    IFS="${_IFS}"
178                    _cmt_escape_compreply
179                fi
180                ;;
181            create)
182                if (( icommand + 3 == COMP_CWORD )); then
183                    return 0
184                    COMPREPLY=( $( compgen -f -- "${cur}" ) )
185                fi
186                ;;
187            expand)
188                if (( icommand + 1 == COMP_CWORD )); then
189                    COMPREPLY=($(compgen -W "model" -- "$cur"))
190                fi
191                ;;
192            remove)
193                if (( icommand + 3 == COMP_CWORD )); then
194                    return 0
195                    COMPREPLY=( $( compgen -f -- "${cur}" ) )
196                elif (( icommand + 1 == COMP_CWORD )); then
197                    COMPREPLY=($(compgen -W "library_links" -- "$cur"))
198                fi
199                ;;
200            show)
201                if (( icommand + 1 == COMP_CWORD )); then
202                    COMPREPLY=($(compgen -W "${show_subcmds[*]}" -- "$cur"))
203                fi
204                ;;
205            co|checkout)
206                case $3 in
207                    -vd|-d)
208                        IFS=$'\n'
209                        COMPREPLY=( $( compgen -d -- "${cur}" ) )
210                        IFS="${_IFS}"
211                        _cmt_escape_compreply
212                        ;;
213                    -requirements)
214                        return 0
215                        COMPREPLY=( $( compgen -f -- "${cur}" ) )
216                        ;;
217                    *)
218                        COMPREPLY=($(compgen -W "-l -R -r -C -i -vd -d -o -requirements -no_config -rs --help" -- "${cur}"))
219                        ;;
220#               COMPREPLY=($(compgen -P "-" -W "l R r C i vd d o requirements no_config rs -help" -- ${cur#-}))
221                esac
222                ;;
223        esac
224    else
225        if [[ ${COMP_LINE:0:${COMP_POINT}} =~ ^.*-((path|f)=|(use)=([^:]+:){2}) ]] ; then
226            p=${COMP_LINE:${#BASH_REMATCH[0]}:$(($COMP_POINT - ${#BASH_REMATCH[0]}))}
227            [ ${#p} -eq 0 ] && return 0
228            eval mwds=(${p}) 2>/dev/null || return 0
229            [ ${#mwds[*]} -le 1 ] && [ -n "${cur}" ] && return 0
230        fi
231        if [ "$3" = make ]; then
232            wordlist="$(cmt -quiet show constituent_names)"
233            wordlist="${wordlist} $(cmt -quiet show groups)"
234            wordlist="${wordlist} check all binclean help"
235            COMPREPLY=($(compgen -W "${wordlist}" -- "$cur"))
236            return 0
237        fi
238        wordlist="${global_opts[*]} ${commands[*]}"
239        COMPREPLY=($(compgen -W "${wordlist}" -- "$cur"))
240    fi
241   
242    return 0
243}
244
245complete -o default -F _cmt cmt
Note: See TracBrowser for help on using the repository browser.