summaryrefslogtreecommitdiffstats
path: root/completions/7z
diff options
context:
space:
mode:
Diffstat (limited to 'completions/7z')
-rw-r--r--completions/7z80
1 files changed, 34 insertions, 46 deletions
diff --git a/completions/7z b/completions/7z
index a8acbc5..027f84b 100644
--- a/completions/7z
+++ b/completions/7z
@@ -1,21 +1,21 @@
# 7z(1) completion -*- shell-script -*-
-_7z()
+_comp_cmd_7z()
{
- local cur prev words cword
- _init_completion -n = || return
+ local cur prev words cword comp_args
+ _comp_initialize -n = -- "$@" || return
if ((cword == 1)); then
- COMPREPLY=($(compgen -W 'a b d e l t u x' -- "$cur"))
+ _comp_compgen -- -W 'a b d e h i l rn t u x'
return
fi
local mode
- [[ ${words[1]} == [adu] ]] && mode=w || mode=r
+ [[ ${words[1]} == @(a|d|rn|u) ]] && mode=w || mode=r
case $cur in
-ao*)
- COMPREPLY=($(compgen -P${cur:0:3} -W 'a s t u' -- "${cur:3}"))
+ _comp_compgen -c "${cur:3}" -- -P"${cur:0:3}" -W 'a s t u'
return
;;
-?(a)[ix]*)
@@ -26,59 +26,48 @@ _7z()
opt=${cur:0:2} cur=${cur:2}
fi
if [[ $cur != *[@\!]* ]]; then
- COMPREPLY=($(compgen -P$opt -W '@ ! r@ r-@ r0@ r! r-! r0!' \
- -- "$cur"))
+ _comp_compgen -- -P"$opt" -W '@ ! r@ r-@ r0@ r! r-! r0!'
elif [[ $cur == ?(r@(-|0|))@* ]]; then
- local IFS=$' \t\n' reset=$(shopt -po noglob)
- set -o noglob
- COMPREPLY=($(compgen -P"${opt}${cur%%@*}@" -f -- "${cur#*@}"))
- $reset
+ _comp_compgen -c "${cur#*@}" -- -P"${opt}${cur%%@*}@" -f
compopt -o filenames
fi
return
;;
-mhe=* | -mhc=* | -ms=* | -mt=*)
- COMPREPLY=($(compgen -W 'on off' -- "${cur#*=}"))
+ _comp_compgen -c "${cur#*=}" -- -W 'on off'
return
;;
-mx=*)
- COMPREPLY=($(compgen -W '0 1 3 5 7 9' -- "${cur#*=}"))
+ _comp_compgen -c "${cur#*=}" -- -W '0 1 3 5 7 9'
return
;;
-o* | -w?*)
- local reset=$(shopt -po noglob)
- set -o noglob
compopt -o filenames
- local ifs=$IFS IFS=$'\n'
- COMPREPLY=($(compgen -d -P${cur:0:2} -S/ -- "${cur:2}"))
- IFS=$ifs
- $reset
+ _comp_compgen -c "${cur:2}" -- -d -P"${cur:0:2}" -S/
compopt -o nospace
return
;;
-r?*)
- COMPREPLY=($(compgen -P${cur:0:2} -W '- 0' -- "${cur:2}"))
+ _comp_compgen -c "${cur:2}" -- -P"${cur:0:2}" -W '- 0'
return
;;
-scs*)
- COMPREPLY=($(compgen -P${cur:0:4} -W 'UTF-8 WIN DOS' \
- -- "${cur:4}"))
+ _comp_compgen -c "${cur:4}" -- -P"${cur:0:4}" -W 'UTF-8 WIN DOS'
return
;;
-ssc?*)
- COMPREPLY=($(compgen -P${cur:0:4} -W '-' -- "${cur:4}"))
+ _comp_compgen -c "${cur:4}" -- -P"${cur:0:4}" -W '-'
return
;;
-t*)
if [[ $mode == w ]]; then
- COMPREPLY=($(compgen -P${cur:0:2} -W '7z bzip2 gzip swfc
- tar wim xz zip' -- "${cur:2}"))
+ _comp_compgen -c "${cur:2}" -- -P"${cur:0:2}" -W '7z bzip2 gzip
+ swfc tar wim xz zip'
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}"))
+ _comp_compgen -c "${cur:2}" -- -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'
fi
return
;;
@@ -88,18 +77,17 @@ _7z()
esac
if [[ $cur == -* ]]; then
- 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"))
+ _comp_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'
[[ ${COMPREPLY-} == -@(an|bd|sfx|si|slt|so|ssc|[rwy]) ]] ||
compopt -o nospace
return
fi
- local args
- _count_args =
- if ((args == 2)); then
- _filedir_xspec unzip
+ local REPLY
+ _comp_count_args
+ if ((REPLY == 2)); then
+ _comp_compgen_filedir_xspec unzip
# TODO: parsing 7z i output?
# - how to figure out if the format is input or output?
# - find string Formats:, read until next empty line
@@ -109,20 +97,20 @@ _7z()
# - terminate on token containing anything [^a-z0-9]
# (assumption: extensions are all lowercase)
[[ $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)|msi|pmd|[rx]ar|rpm|sw[fm]|?(g)tar|taz|?(t)[bglx]z|tb?(z)2|vhd|wim|Z)'
+ _comp_compgen -a filedir '@(7z|bz2|swf|?(g)tar|?(t)[bglx]z|tb?(z)2|wim)' ||
+ _comp_compgen -a filedir '@(7z?(.001)|arj|bz2|cab|cb7|chm|cpio|deb|dmg|flv|gem|img|iso|lz[ah]|lzma?(86)|msi|pmd|[rx]ar|rpm|sw[fm]|?(g)tar|taz|?(t)[bglx]z|tb?(z)2|vhd|wim|Z)'
else
if [[ ${words[1]} == d ]]; then
- local IFS=$'\n'
- COMPREPLY=($(compgen -W "$(printf '%s\n' "$($1 l ${words[2]} \
- -slt 2>/dev/null | command sed -n '/^Path =/s/^Path = \(.*\)$/\1/p' \
- 2>/dev/null | tail -n+2)")" -- "$cur"))
+ _comp_compgen_split -l -- "$(
+ "$1" l "${words[2]}" -slt 2>/dev/null | command sed -n \
+ '/^Path =/s/^Path = \(.*\)$/\1/p' 2>/dev/null | tail -n+2
+ )"
compopt -o filenames
else
- _filedir
+ _comp_compgen_filedir
fi
fi
} &&
- complete -F _7z 7z 7za
+ complete -F _comp_cmd_7z 7z 7za 7zr 7zz 7zzs
# ex: filetype=sh