50 lines
1.2 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()
{
local cur prev words cword
_init_completion || return
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
local helpopts=`_parse_help ${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' 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=
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