• 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            *)
16                ;;
17        esac
18    done
19
20    case "${cmd}" in
21        my__app)
22            opts="-F -f -O -o -h -V --flg --flag --opt --option --help --version [positional]"
23            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
24                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
25                return 0
26            fi
27            case "${prev}" in
28                --option)
29                    COMPREPLY=($(compgen -f "${cur}"))
30                    return 0
31                    ;;
32                --opt)
33                    COMPREPLY=($(compgen -f "${cur}"))
34                    return 0
35                    ;;
36                -o)
37                    COMPREPLY=($(compgen -f "${cur}"))
38                    return 0
39                    ;;
40                -O)
41                    COMPREPLY=($(compgen -f "${cur}"))
42                    return 0
43                    ;;
44                *)
45                    COMPREPLY=()
46                    ;;
47            esac
48            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
49            return 0
50            ;;
51    esac
52}
53
54complete -F _my-app -o bashdefault -o default my-app
55