120 lines
3.8 KiB
Plaintext
Raw Normal View History

2013-06-15 00:34:08 +03:00
# 7z(1) completion -*- shell-script -*-
_7z()
{
local cur prev words cword
_init_completion -n = || return
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'a b d e l t u x' -- "$cur" ) )
return
fi
2013-09-13 02:26:10 +04:00
local mode
2014-07-19 19:15:49 +03:00
[[ ${words[1]} == [adu] ]] && mode=w || mode=r
2013-09-13 02:26:10 +04:00
2013-06-15 00:34:08 +03:00
case $cur in
2013-09-13 02:26:10 +04:00
-ao*)
COMPREPLY=( $( compgen -P${cur:0:3} -W 'a s t u' -- "${cur:3}" ) )
return
;;
-?(a)[ix]*)
local opt
if [[ $cur == -a[ix]* ]]; then
opt=${cur:0:3} cur=${cur:3}
else
opt=${cur:0:2} cur=${cur:2}
fi
if [[ $cur != *[@\!]* ]]; then
COMPREPLY=( $( compgen -P$opt -W '@ ! r@ r-@ r0@ r! r-! r0!' \
-- "$cur" ) )
elif [[ $cur == ?(r@(-|0|))@* ]]; then
local x tmp
x=$( compgen -P"${opt}${cur%%@*}@" -f -- "${cur#*@}" ) &&
while read -r tmp; do
COMPREPLY+=( "$tmp" )
done <<< "$x"
compopt -o filenames
fi
return
;;
-mhe=*|-mhc=*|-ms=*|-mt=*)
2013-06-15 00:34:08 +03:00
COMPREPLY=( $( compgen -W 'on off' -- "${cur#*=}" ) )
return
;;
2013-09-13 02:26:10 +04:00
-mx=*)
COMPREPLY=( $( compgen -W '0 1 3 5 7 9' -- "${cur#*=}" ) )
return
;;
2013-06-15 00:34:08 +03:00
-o*|-w?*)
2013-09-13 02:26:10 +04:00
local x tmp
x=$( compgen -P${cur:0:2} -S/ -d -- "${cur:2}" ) &&
while read -r tmp; do
COMPREPLY+=( "$tmp" )
done <<< "$x"
2013-06-15 00:34:08 +03:00
compopt -o nospace -o filenames
return
;;
-r?*)
COMPREPLY=( $( compgen -P${cur:0:2} -W '- 0' -- "${cur:2}" ) )
return
;;
-scs*)
COMPREPLY=( $( compgen -P${cur:0:4} -W 'UTF-8 WIN DOS' \
-- "${cur:4}" ) )
return
;;
-ssc?*)
COMPREPLY=( $( compgen -P${cur:0:4} -W '-' -- "${cur:4}" ) )
return
;;
-t*)
2013-09-13 02:26:10 +04:00
if [[ $mode == w ]]; then
COMPREPLY=( $( compgen -P${cur:0:2} -W '7z bzip2 gzip swfc
tar wim xz zip' -- "${cur:2}" ) )
else
COMPREPLY=( $( compgen -P${cur:0:2} -W '7z apm arj bzip2 cab
chm cpio cramfs deb dmg elf fat flv gzip hfs iso lzh lzma
lzma86 macho mbr mslz mub nsis ntfs pe ppmd rar rpm
squashfs swf swfc tar udf vhd wim xar xz z zip' \
-- "${cur:2}" ) )
fi
2013-06-15 00:34:08 +03:00
return
;;
2013-09-13 02:26:10 +04:00
-m*=*|-p*|-u*|-v*)
2013-06-15 00:34:08 +03:00
return
;;
esac
if [[ $cur == -* ]]; then
2013-09-13 02:26:10 +04:00
COMPREPLY=( $( compgen -W '-ai -an -ao -ax -bd -i -m{x,s,f,he,hc,mt}=
-o -p -r -scs -sfx -si -slp -slt -so -ssc -t -u -v -w -x -y' \
-- "$cur" ) )
[[ $COMPREPLY == -@(an|bd|sfx|si|slt|so|ssc|[rwy]) ]] ||
compopt -o nospace
2013-06-15 00:34:08 +03:00
return
fi
local args
_count_args =
if [[ $args -eq 2 ]]; then
_filedir_xspec unzip
2013-09-13 02:26:10 +04:00
[[ $mode == w ]] &&
_filedir '@(7z|bz2|swf|?(g)tar|?(t)[bglx]z|tb?(z)2|wim)' ||
_filedir '@(7z|arj|bz2|cab|chm|cpio|deb|dmg|flv|gem|img|iso|lz[ah]|lzma?(86)|pmd|[rx]ar|rpm|sw[fm]|?(g)tar|taz|?(t)[bglx]z|tb?(z)2|vhd|wim|Z)'
2013-06-15 00:34:08 +03:00
else
2013-09-13 02:26:10 +04:00
if [[ ${words[1]} == d ]]; then
local IFS=$'\n'
COMPREPLY=( $( compgen -W "$( printf '%s\n' $( $1 l ${words[2]} \
2013-09-13 02:26:10 +04:00
-slt 2>/dev/null | sed -n '/^Path =/s/^Path = \(.*\)$/\1/p' \
2>/dev/null | tail -n+2 ) )" -- "$cur" ) )
compopt -o filenames
else
_filedir
fi
2013-06-15 00:34:08 +03:00
fi
} &&
complete -F _7z 7z 7za
# ex: ts=4 sw=4 et filetype=sh