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,cmd-backslash) 16 cmd="my__app__cmd__backslash" 17 ;; 18 my__app,cmd-backticks) 19 cmd="my__app__cmd__backticks" 20 ;; 21 my__app,cmd-brackets) 22 cmd="my__app__cmd__brackets" 23 ;; 24 my__app,cmd-double-quotes) 25 cmd="my__app__cmd__double__quotes" 26 ;; 27 my__app,cmd-expansions) 28 cmd="my__app__cmd__expansions" 29 ;; 30 my__app,cmd-single-quotes) 31 cmd="my__app__cmd__single__quotes" 32 ;; 33 my__app,help) 34 cmd="my__app__help" 35 ;; 36 my__app__help,cmd-backslash) 37 cmd="my__app__help__cmd__backslash" 38 ;; 39 my__app__help,cmd-backticks) 40 cmd="my__app__help__cmd__backticks" 41 ;; 42 my__app__help,cmd-brackets) 43 cmd="my__app__help__cmd__brackets" 44 ;; 45 my__app__help,cmd-double-quotes) 46 cmd="my__app__help__cmd__double__quotes" 47 ;; 48 my__app__help,cmd-expansions) 49 cmd="my__app__help__cmd__expansions" 50 ;; 51 my__app__help,cmd-single-quotes) 52 cmd="my__app__help__cmd__single__quotes" 53 ;; 54 my__app__help,help) 55 cmd="my__app__help__help" 56 ;; 57 *) 58 ;; 59 esac 60 done 61 62 case "${cmd}" in 63 my__app) 64 opts="-h -V --single-quotes --double-quotes --backticks --backslash --brackets --expansions --help --version cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" 65 if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then 66 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 67 return 0 68 fi 69 case "${prev}" in 70 *) 71 COMPREPLY=() 72 ;; 73 esac 74 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 75 return 0 76 ;; 77 my__app__cmd__backslash) 78 opts="-h --help" 79 if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then 80 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 81 return 0 82 fi 83 case "${prev}" in 84 *) 85 COMPREPLY=() 86 ;; 87 esac 88 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 89 return 0 90 ;; 91 my__app__cmd__backticks) 92 opts="-h --help" 93 if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then 94 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 95 return 0 96 fi 97 case "${prev}" in 98 *) 99 COMPREPLY=() 100 ;; 101 esac 102 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 103 return 0 104 ;; 105 my__app__cmd__brackets) 106 opts="-h --help" 107 if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then 108 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 109 return 0 110 fi 111 case "${prev}" in 112 *) 113 COMPREPLY=() 114 ;; 115 esac 116 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 117 return 0 118 ;; 119 my__app__cmd__double__quotes) 120 opts="-h --help" 121 if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then 122 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 123 return 0 124 fi 125 case "${prev}" in 126 *) 127 COMPREPLY=() 128 ;; 129 esac 130 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 131 return 0 132 ;; 133 my__app__cmd__expansions) 134 opts="-h --help" 135 if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then 136 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 137 return 0 138 fi 139 case "${prev}" in 140 *) 141 COMPREPLY=() 142 ;; 143 esac 144 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 145 return 0 146 ;; 147 my__app__cmd__single__quotes) 148 opts="-h --help" 149 if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then 150 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 151 return 0 152 fi 153 case "${prev}" in 154 *) 155 COMPREPLY=() 156 ;; 157 esac 158 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 159 return 0 160 ;; 161 my__app__help) 162 opts="cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" 163 if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then 164 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 165 return 0 166 fi 167 case "${prev}" in 168 *) 169 COMPREPLY=() 170 ;; 171 esac 172 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 173 return 0 174 ;; 175 my__app__help__cmd__backslash) 176 opts="" 177 if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then 178 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 179 return 0 180 fi 181 case "${prev}" in 182 *) 183 COMPREPLY=() 184 ;; 185 esac 186 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 187 return 0 188 ;; 189 my__app__help__cmd__backticks) 190 opts="" 191 if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then 192 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 193 return 0 194 fi 195 case "${prev}" in 196 *) 197 COMPREPLY=() 198 ;; 199 esac 200 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 201 return 0 202 ;; 203 my__app__help__cmd__brackets) 204 opts="" 205 if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then 206 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 207 return 0 208 fi 209 case "${prev}" in 210 *) 211 COMPREPLY=() 212 ;; 213 esac 214 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 215 return 0 216 ;; 217 my__app__help__cmd__double__quotes) 218 opts="" 219 if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then 220 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 221 return 0 222 fi 223 case "${prev}" in 224 *) 225 COMPREPLY=() 226 ;; 227 esac 228 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 229 return 0 230 ;; 231 my__app__help__cmd__expansions) 232 opts="" 233 if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then 234 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 235 return 0 236 fi 237 case "${prev}" in 238 *) 239 COMPREPLY=() 240 ;; 241 esac 242 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 243 return 0 244 ;; 245 my__app__help__cmd__single__quotes) 246 opts="" 247 if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then 248 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 249 return 0 250 fi 251 case "${prev}" in 252 *) 253 COMPREPLY=() 254 ;; 255 esac 256 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 257 return 0 258 ;; 259 my__app__help__help) 260 opts="" 261 if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then 262 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 263 return 0 264 fi 265 case "${prev}" in 266 *) 267 COMPREPLY=() 268 ;; 269 esac 270 COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) 271 return 0 272 ;; 273 esac 274} 275 276complete -F _my-app -o bashdefault -o default my-app 277