summaryrefslogtreecommitdiff
path: root/contrib/bash-builtins
blob: 61c9d8d4ed3319ef8bffea9c1d0734b6007967d2 (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
121
122
123
124
125
126
127
128
129
130
# bash alias completion
#
_alias()
{
    local cur

    COMPREPLY=()
    cur=`_get_cword`

    case $COMP_LINE 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

    COMPREPLY=()
    cur=`_get_cword`

    case $COMP_LINE 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

    COMPREPLY=()
    cur=`_get_cword`
    prev=${COMP_WORDS[COMP_CWORD-1]}

    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 [ $COMP_CWORD -eq 1 ]; then
        COMPREPLY=( $( compgen -A function -- "$cur" ) )
    else
        COMPREPLY=( "() $( type -- ${COMP_WORDS[1]} | sed -e 1,2d )" )
    fi
}
complete -F _function function declare typeset

# bash complete completion
#
_complete()
{
    local cur prev

    COMPREPLY=()
    cur=`_get_cword`
    prev=${COMP_WORDS[COMP_CWORD-1]}

    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
        COMPREPLY=( $( compgen -W '-a -b -c -d -e -f -g -j -k -o -s -v -u -A \
            -G -W -P -S -X -F -C' -- "$cur" ) )
    else
        COMPREPLY=( $( compgen -A command -- "$cur" ) )
    fi
}
complete -F _complete 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