summaryrefslogtreecommitdiffstats
path: root/completions/complete
blob: 74ae3f9f6a48b79ae733ecfa91d434786afb47ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# bash complete completion                                 -*- shell-script -*-

_comp_cmd_complete()
{
    local cur prev words cword comp_args
    _comp_initialize -- "$@" || return

    case $prev in
        -*o)
            _comp_compgen -- -W 'bashdefault default dirnames filenames nospace
                plusdirs'
            return
            ;;

        -*A)
            _comp_compgen -- -W 'alias arrayvar binding builtin command
                directory disabled enabled export file function group helptopic
                hostname job keyword running service setopt shopt signal
                stopped user variable'
            return
            ;;

        -*C)
            _comp_compgen -- -A command
            return
            ;;
        -*F)
            _comp_compgen -- -A function
            return
            ;;
        -*p | -*r)
            _comp_compgen_split -l -- "$(complete -p | command sed -e 's|.* ||')"
            return
            ;;
    esac

    if [[ $cur == -* ]]; then
        local -a opts
        _comp_compgen -v opts usage -c help -s "$1"
        # -F, -C do not work the expected way with compgen
        [[ $1 != *compgen ]] || opts=("${opts[@]//-[FC]/}")
        _comp_compgen -- -W '"${opts[@]}"' -X ''
    else
        _comp_compgen -- -A command
    fi
} &&
    complete -F _comp_cmd_complete compgen complete

# ex: filetype=sh