• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1_my-app() {
2    local i cur prev opts cmd
3    COMPREPLY=()
4    cur="${COMP_WORDS[COMP_CWORD]}"
5    prev="${COMP_WORDS[COMP_CWORD-1]}"
6    cmd=""
7    opts=""
8
9    for i in ${COMP_WORDS[@]}
10    do
11        case "${cmd},${i}" in
12            ",$1")
13                cmd="my__app"
14                ;;
15            my__app,help)
16                cmd="my__app__help"
17                ;;
18            my__app,some-cmd-with-hyphens)
19                cmd="my__app__some__cmd__with__hyphens"
20                ;;
21            my__app,some-hidden-cmd)
22                cmd="my__app__some__hidden__cmd"
23                ;;
24            my__app,some_cmd)
25                cmd="my__app__some_cmd"
26                ;;
27            my__app,test)
28                cmd="my__app__test"
29                ;;
30            my__app__help,help)
31                cmd="my__app__help__help"
32                ;;
33            my__app__help,some-cmd-with-hyphens)
34                cmd="my__app__help__some__cmd__with__hyphens"
35                ;;
36            my__app__help,some-hidden-cmd)
37                cmd="my__app__help__some__hidden__cmd"
38                ;;
39            my__app__help,some_cmd)
40                cmd="my__app__help__some_cmd"
41                ;;
42            my__app__help,test)
43                cmd="my__app__help__test"
44                ;;
45            *)
46                ;;
47        esac
48    done
49
50    case "${cmd}" in
51        my__app)
52            opts="-C -c -h -V --conf --config --help --version [file] first second test some_cmd some-cmd-with-hyphens some-hidden-cmd help"
53            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
54                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
55                return 0
56            fi
57            case "${prev}" in
58                *)
59                    COMPREPLY=()
60                    ;;
61            esac
62            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
63            return 0
64            ;;
65        my__app__help)
66            opts="test some_cmd some-cmd-with-hyphens some-hidden-cmd help"
67            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
68                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
69                return 0
70            fi
71            case "${prev}" in
72                *)
73                    COMPREPLY=()
74                    ;;
75            esac
76            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
77            return 0
78            ;;
79        my__app__help__help)
80            opts=""
81            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
82                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
83                return 0
84            fi
85            case "${prev}" in
86                *)
87                    COMPREPLY=()
88                    ;;
89            esac
90            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
91            return 0
92            ;;
93        my__app__help__some__cmd__with__hyphens)
94            opts=""
95            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
96                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
97                return 0
98            fi
99            case "${prev}" in
100                *)
101                    COMPREPLY=()
102                    ;;
103            esac
104            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
105            return 0
106            ;;
107        my__app__help__some__hidden__cmd)
108            opts=""
109            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
110                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
111                return 0
112            fi
113            case "${prev}" in
114                *)
115                    COMPREPLY=()
116                    ;;
117            esac
118            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
119            return 0
120            ;;
121        my__app__help__some_cmd)
122            opts=""
123            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
124                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
125                return 0
126            fi
127            case "${prev}" in
128                *)
129                    COMPREPLY=()
130                    ;;
131            esac
132            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
133            return 0
134            ;;
135        my__app__help__test)
136            opts=""
137            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
138                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
139                return 0
140            fi
141            case "${prev}" in
142                *)
143                    COMPREPLY=()
144                    ;;
145            esac
146            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
147            return 0
148            ;;
149        my__app__some__cmd__with__hyphens)
150            opts="-h -V --help --version"
151            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
152                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
153                return 0
154            fi
155            case "${prev}" in
156                *)
157                    COMPREPLY=()
158                    ;;
159            esac
160            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
161            return 0
162            ;;
163        my__app__some__hidden__cmd)
164            opts="-h -V --help --version"
165            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
166                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
167                return 0
168            fi
169            case "${prev}" in
170                *)
171                    COMPREPLY=()
172                    ;;
173            esac
174            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
175            return 0
176            ;;
177        my__app__some_cmd)
178            opts="-h -V --config --help --version [path]..."
179            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
180                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
181                return 0
182            fi
183            case "${prev}" in
184                --config)
185                    COMPREPLY=($(compgen -f "${cur}"))
186                    return 0
187                    ;;
188                *)
189                    COMPREPLY=()
190                    ;;
191            esac
192            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
193            return 0
194            ;;
195        my__app__test)
196            opts="-h -V --case --help --version"
197            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
198                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
199                return 0
200            fi
201            case "${prev}" in
202                --case)
203                    COMPREPLY=($(compgen -f "${cur}"))
204                    return 0
205                    ;;
206                *)
207                    COMPREPLY=()
208                    ;;
209            esac
210            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
211            return 0
212            ;;
213    esac
214}
215
216complete -F _my-app -o bashdefault -o default my-app
217