diff --git a/completions/.gitignore b/completions/.gitignore index 3b76ba48..32910904 100644 --- a/completions/.gitignore +++ b/completions/.gitignore @@ -1,3 +1,4 @@ +7za aclocal-1.1[0123] alpine alternatives diff --git a/completions/7z b/completions/7z new file mode 100644 index 00000000..a4b086c0 --- /dev/null +++ b/completions/7z @@ -0,0 +1,64 @@ +# 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 + + case $cur in + -mhe=*) + COMPREPLY=( $( compgen -W 'on off' -- "${cur#*=}" ) ) + return + ;; + -o*|-w?*) + compopt -o nospace -o filenames + COMPREPLY=( $( compgen -P${cur:0:2} -S/ -d -- "${cur:2}" ) ) + 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*) + COMPREPLY=( $( compgen -P${cur:0:2} -W '7z zip gzip bzip2 tar' \ + -- "${cur:2}" ) ) + return + ;; + -a*|-i*|-m*|-p*|-u*|-v*|-x*) + return + ;; + esac + + if [[ $cur == -* ]]; then + COMPREPLY=( $( compgen -W '-ai -ax -bd -i -m -o -p -r -scs -sfx -si + -slt -so -ssc -t -u -v -w -x -y' -- "$cur" ) ) + [[ $COMPREPLY == -@(bd|sfx|si|slt|so|ssc|[rwy]) ]] || compopt -o nospace + return + fi + + local args + _count_args = + if [[ $args -eq 2 ]]; then + _filedir_xspec unzip + _filedir '@(7z|arj|bz2|cab|cpio|deb|gem|?(g)tar|?(t)[bg]z|tb?(z)2|rpm)' + else + _filedir + fi +} && +complete -F _7z 7z 7za + +# ex: ts=4 sw=4 et filetype=sh diff --git a/completions/Makefile.am b/completions/Makefile.am index 0e604f07..899ef850 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -1,5 +1,6 @@ bashcompdir = $(pkgdatadir)/completions -bashcomp_DATA = a2x \ +bashcomp_DATA = 7z \ + a2x \ abook \ aclocal \ acpi \ @@ -382,6 +383,7 @@ EXTRA_DIST = $(bashcomp_DATA) \ _mock _modules _nmcli _subversion _udevadm _yum _yum-utils CLEANFILES = \ + 7za \ aclocal-1.10 \ aclocal-1.11 \ aclocal-1.12 \ @@ -576,6 +578,10 @@ CLEANFILES = \ ypcat symlinks: $(targetdir) $(DATA) + for file in 7za ; do \ + rm -f $(targetdir)/$$file && \ + $(LN_S) 7z $(targetdir)/$$file ; \ + done for file in aclocal-1.10 aclocal-1.11 aclocal-1.12 aclocal-1.13 ; do \ rm -f $(targetdir)/$$file && \ $(LN_S) aclocal $(targetdir)/$$file ; \ diff --git a/test/completion/7z.exp b/test/completion/7z.exp new file mode 100644 index 00000000..0796b7a5 --- /dev/null +++ b/test/completion/7z.exp @@ -0,0 +1 @@ +assert_source_completions 7z diff --git a/test/lib/completions/7z.exp b/test/lib/completions/7z.exp new file mode 100644 index 00000000..08d6bf12 --- /dev/null +++ b/test/lib/completions/7z.exp @@ -0,0 +1,18 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "7z " +sync_after_int + + +teardown