summaryrefslogtreecommitdiff
path: root/contrib/gzip
blob: 48f97011f2dee869417c5a38149aac44bfbe10bf (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
# bash completion for gzip

have gzip &&
_gzip()
{
    local cur prev xspec helpopts

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

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $( compgen -W "$helpopts -2 -3 -4 -5 -6 -7 -8" -- "$cur" ) )
        return 0
    fi

    local IFS=$'\t\n'

    xspec="*.?(t)gz"
    if [[ "$prev" == --* ]]; then
        [[ "$prev" == --decompress || \
            "$prev" == --list || \
            "$prev" == --test ]] && xspec="!"$xspec
        [[ "$prev" == --force ]] && xspec=
    elif [[ "$prev" == -* ]]; then
        [[ "$prev" == -*[dlt]* ]] && xspec="!"$xspec
        [[ "$prev" == -*f* ]] && xspec=
    elif [[ "$prev" == '>' || "$prev" == '>>' ]]; then
        xspec=
    elif [ "$prev" = '<' ]; then
        xspec=
    fi

    _expand || return 0

    COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
        $( compgen -d -- "$cur" ) )
} &&
complete -F _gzip -o filenames gzip

# 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