summaryrefslogtreecommitdiff
path: root/completions/export
blob: 8d823614aafbff48b14c2166a473113dc51e3302 (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
65
# bash export completion                                   -*- shell-script -*-

_export()
{
    local cur prev words cword
    _init_completion -n = || return

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

    if [[ $cur == *=* ]]; then
        local ocur=$cur oprev=$prev
        prev=${cur%%=*} cur=${cur#*=}
        _variables && return
        cur=$ocur prev=$oprev
    fi

    case $cur in
        *=)
            local pval=$(quote "$(eval printf %s \"\$\{${cur%=}-\}\")")
            # Complete previous value if it's not empty.
            if [[ $pval != \'\' ]]; then
                COMPREPLY=("$pval")
            else
                cur=${cur#*=}
                _filedir
            fi
            ;;
        *=*)
            cur=${cur#*=}
            _filedir
            ;;
        *)
            if [[ $cword -eq 1 && $cur == -* ]]; then
                COMPREPLY=($(compgen -W '-p $(_parse_usage "$1")' -- "$cur"))
                return
            fi
            local suffix=""
            if ! $remove; then
                suffix="="
                compopt -o nospace
            fi
            COMPREPLY=($(compgen -A $action -S "$suffix" -- "$cur"))
            ;;
    esac
} &&
    complete -F _export export

# ex: filetype=sh