summaryrefslogtreecommitdiffstats
path: root/completions/gzip
blob: 9a41eecabe5d50978cecd52206582c7160d8f0a4 (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                                 -*- shell-script -*-

_comp_cmd_gzip()
{
    local cur prev words cword comp_args
    _comp_initialize -- "$@" || return

    local noargopts='!(-*|*[bSACIJp]*)'
    # shellcheck disable=SC2254
    case $prev in
        --blocksize | --suffix | --help | --version | --alias | --comment | \
            --iterations | --maxsplits | -${noargopts}[bShVACIJ])
            return
            ;;
        --processes | -${noargopts}p)
            local REPLY
            _comp_get_ncpus
            _comp_compgen -- -W "{1..$REPLY}"
            return
            ;;
    esac

    if [[ $cur == -* ]]; then
        _comp_compgen_help
        _comp_compgen -a -- -W '-{1..9}'
        [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
        return
    fi

    local xspec="*.@(gz|t[ag]z)"
    [[ ${1##*/} == pigz ]] && xspec="*.@([gz]z|t[ag]z)"

    if [[ $prev == --* ]]; then
        [[ $prev == --@(decompress|list|test) ]] && xspec="!"$xspec
        [[ $prev == --force ]] && xspec=
    elif [[ $prev == -* ]]; then
        [[ $prev == -*[dlt]* ]] && xspec="!"$xspec
        [[ $prev == -*f* ]] && xspec=
    fi

    _comp_compgen_tilde && return

    compopt -o filenames
    _comp_compgen -- -f -X "$xspec" -o plusdirs
} &&
    complete -F _comp_cmd_gzip gzip pigz

# ex: filetype=sh