summaryrefslogtreecommitdiffstats
path: root/completions/export
blob: 0f692c9861c314caa224446494494d21750a2be6 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# bash export completion                                   -*- shell-script -*-

_comp_cmd_export()
{
    local cur prev words cword comp_args
    _comp_initialize -n := -- "$@" || return

    local i action=variable remove=""
    for ((i = 1; i < cword; i++)); do
        case ${words[i]} in
            -p)
                return
                ;;
            -*f*)
                action=function
                ;;&
            -*n*)
                remove=set
                ;;
            -*)
                continue
                ;;
        esac
        break
    done

    if [[ $cur == *=* ]]; then
        _comp_variable_assignments "$cur" && return
    fi

    case $cur in
        *=)
            local pname=${cur%=}
            local REPLY
            _comp_quote "${!pname-}"
            local pval=$REPLY
            # Complete previous value if it's not empty.
            if [[ $pval != \'\' ]]; then
                COMPREPLY=("$pval")
            else
                _comp_compgen -c "${cur#*=}" filedir
            fi
            ;;
        *=*)
            _comp_compgen -c "${cur#*=}" filedir
            ;;
        *)
            if [[ $cword -eq 1 && $cur == -* ]]; then
                _comp_compgen_usage -c help -s "$1"
                _comp_compgen -a -- -W '-p'
                return
            fi
            local suffix=""
            if [[ ! $remove && $action != function ]]; then
                suffix="="
                compopt -o nospace
            fi
            _comp_compgen -- -A $action -S "$suffix"
            ;;
    esac
} &&
    complete -F _comp_cmd_export export

# ex: filetype=sh