• 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,test)
19                cmd="my__app__test"
20                ;;
21            my__app__help,help)
22                cmd="my__app__help__help"
23                ;;
24            my__app__help,test)
25                cmd="my__app__help__test"
26                ;;
27            *)
28                ;;
29        esac
30    done
31
32    case "${cmd}" in
33        my__app)
34            opts="-c -v -h --help test help"
35            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
36                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
37                return 0
38            fi
39            case "${prev}" in
40                *)
41                    COMPREPLY=()
42                    ;;
43            esac
44            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
45            return 0
46            ;;
47        my__app__help)
48            opts="test help"
49            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
50                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
51                return 0
52            fi
53            case "${prev}" in
54                *)
55                    COMPREPLY=()
56                    ;;
57            esac
58            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
59            return 0
60            ;;
61        my__app__help__help)
62            opts=""
63            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
64                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
65                return 0
66            fi
67            case "${prev}" in
68                *)
69                    COMPREPLY=()
70                    ;;
71            esac
72            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
73            return 0
74            ;;
75        my__app__help__test)
76            opts=""
77            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
78                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
79                return 0
80            fi
81            case "${prev}" in
82                *)
83                    COMPREPLY=()
84                    ;;
85            esac
86            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
87            return 0
88            ;;
89        my__app__test)
90            opts="-d -c -h --help"
91            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
92                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
93                return 0
94            fi
95            case "${prev}" in
96                *)
97                    COMPREPLY=()
98                    ;;
99            esac
100            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
101            return 0
102            ;;
103    esac
104}
105
106complete -F _my-app -o bashdefault -o default my-app
107