57 lines
1.3 KiB
Plaintext
Raw Normal View History

2009-05-17 22:01:43 +02:00
# bash completion for gzip
have gzip || have pigz || return
2009-05-17 22:01:43 +02:00
_gzip()
{
2011-04-16 20:42:43 +03:00
local cur prev xspec
2009-10-04 19:42:50 +02:00
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in
-b|--blocksize|-p|--processes|-S|--suffix|-h|--help|-V|--version)
return 0
;;
esac
2009-10-04 19:42:50 +02:00
if [[ "$cur" == -* ]]; then
2011-04-16 20:42:43 +03:00
local helpopts=`_parse_help ${COMP_WORDS[0]}`
COMPREPLY=( $( compgen -W "$helpopts -1 -2 -3 -4 -5 -6 -7 -8 -9" \
-- "$cur" ) )
2009-10-04 19:42:50 +02:00
return 0
fi
local IFS=$'\n'
2009-10-04 19:42:50 +02:00
2010-03-30 22:11:24 +03:00
xspec="*.@(gz|t[ag]z)"
2009-10-04 19:42:50 +02:00
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
2009-10-04 19:42:50 +02:00
xspec=
elif [ "$prev" = '<' ]; then
xspec=
fi
_expand || return 0
_compopt_o_filenames
2009-10-04 19:42:50 +02:00
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) )
2009-05-17 22:01:43 +02:00
} &&
complete -F _gzip gzip pigz
# Local variables:
# mode: shell-script
2009-10-04 19:42:50 +02:00
# sh-basic-offset: 4
# sh-indent-comment: t
2009-10-04 19:42:50 +02:00
# indent-tabs-mode: nil
# End:
2009-10-04 19:42:50 +02:00
# ex: ts=4 sw=4 et filetype=sh