summaryrefslogtreecommitdiff
path: root/completions/bash-builtins
blob: 3df3ddb32db2f1a18287b6c1cec0ff51028e4243 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# bash alias completion
#
_alias()
{
    local cur prev words cword
    _init_completion || return

    case ${words[@]} in
        *[^=])
            COMPREPLY=( $( compgen -A alias -- "$cur" ) )
            ;;
        *=)
            COMPREPLY=( "$( alias ${cur%=} 2>/dev/null | sed \
                -e 's|^alias '"$cur"'\(.*\)$|\1|' )" )
            ;;
    esac
} &&
complete -F _alias -o nospace alias

# bash export completion
#
_export()
{
    local cur prev words cword
    _init_completion || return

    case ${words[@]} in
        *=\$*)
            COMPREPLY=( $( compgen -v -P '$' -- "${cur#*=\$}" ) )
            ;;
        *[^=])
            COMPREPLY=( $( compgen -v -S '=' -- "$cur" ) )
            ;;
        *=)
            COMPREPLY=( "$( eval echo -n \"$`echo ${cur%=}`\" |
                ( echo -n \'
                  sed -e 's/'\''/'\''\\\'\'''\''/g'
                  echo -n \' ) )" )
            ;;
    esac
} &&
complete -F _export -o default -o nospace export

# bash shell function completion
#
_function()
{
    local cur prev words cword
    _init_completion || return

    if [[ $1 == @(declare|typeset) ]]; then
        if [ "$prev" = -f ]; then
            COMPREPLY=( $( compgen -A function -- "$cur" ) )
        elif [[ "$cur" == -* ]]; then
            COMPREPLY=( $( compgen -W '-a -f -F -i -r -x -p' -- "$cur" ) )
        fi
    elif [ $cword -eq 1 ]; then
        COMPREPLY=( $( compgen -A function -- "$cur" ) )
    else
        COMPREPLY=( "() $( type -- ${words[1]} | sed -e 1,2d )" )
    fi
} &&
complete -F _function function declare typeset

# bash complete completion
#
_complete()
{
    local cur prev words cword
    _init_completion || return

    case $prev in
        -o)
            COMPREPLY=( $( compgen -W 'bashdefault default dirnames filenames \
                nospace plusdirs' -- "$cur" ) )
            return 0
            ;;

        -A)
            COMPREPLY=( $( 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' -- "$cur" ) )
            return 0
            ;;

        -C)
            COMPREPLY=( $( compgen -A command -- "$cur" ) )
            return 0
            ;;
        -F)
            COMPREPLY=( $( compgen -A function -- "$cur" ) )
            return 0
            ;;
        -p|-r)
            COMPREPLY=( $( complete -p | sed -e 's|.* ||' ) )
            COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
            return 0
            ;;

    esac

    if [[ "$cur" == -* ]]; then
        # relevant options completion
        local opts="-a -b -c -d -e -f -g -j -k -o -s -u -v -A -G -W -P -S -X"
        [[ $1 != compgen ]] && opts+=" -F -C"
        COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
    else
        COMPREPLY=( $( compgen -A command -- "$cur" ) )
    fi
} &&
complete -F _complete compgen complete

# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh