Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: complete Debian architectures in common function



Quite a few of the Debian completions need to complete the Debian
architectures. This factors that out into _deb_architectures. You can
pass it extra values such as with -a "source all" if those are possible
matches. I've also updated or fixed other areas of affected functions,
particularly _apt-file.

Oliver

diff --git a/Completion/Debian/Command/_apt-file b/Completion/Debian/Command/_apt-file
index eddbbdc..98a93fd 100644
--- a/Completion/Debian/Command/_apt-file
+++ b/Completion/Debian/Command/_apt-file
@@ -1,55 +1,59 @@
 #compdef apt-file
 
-_apt-file() {
-  local -a arguments
-  local state line cmds 
-  arguments=(
-    '(--cache -c)'{--cache,-c}'[cache directory]:directory:_directories'
-    '(-v --verbose)'{-v,--verbose}'[verbose]'
-     '(--cdrom-mount -d)'{--cdrom-mount,-d}'[cdrom mount point]:directory:_directories'
-     '(--ignore-case -i)'{--ignore-case,-i}'[ignore case]'
-     '(--regexp -r)'{--regexp,-r}'[regular expression]'
-     '(-V --version)'{-V,--version}'[version]'
-     '(-a --architecture)'{-a,--architecture}'[architecture]:architecture:(alpha arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)'
-    '(-s --sources-list)'{-s,--sources-list}'[source.list file]:file:_files'
-    '(-l --package-only)'{-l,--package-only}'[only display package name]'
-    '(-F --fixed-string)'{-F,--fixed-string}'[do not expand search pattern]'
-    '(-y --dummy)'{-y,--dummy}'[run in dummy mode]'
-    '(-h --help)'{-h,--help}'[display help screen]'
-    '1: :->cmds'
-    '*: :->args'
-  )
-    _arguments -S $arguments
+local curcontext="$curcontext" state line expl cmds ret=1
+typeset -A opt_args
 
-    case $state in
-      cmds)
-        cmds=(
-            'update:resynchronize package contents'
-            'search:search in which package file is included'
-            'list:list contents of a package'
-            'show:alias for list'
-            'purge:remove all Contents-<ARCH>.gz files in cache directory'
-        )
-        _describe -t commands 'apt-list command' cmds && ret=0
+_arguments -C -S \
+  '(--cache -c)'{--cache,-c}'[cache directory]:directory:_directories' \
+  '(-v --verbose)'{-v,--verbose}'[verbose]' \
+  '(--cdrom-mount -d)'{--cdrom-mount,-d}'[cdrom mount point]:directory:_directories' \
+  '(--from-file -f --from-deb -D)'{--from-file,-f}'[read patterns from given file]' \
+  '(--from-deb -D --from-file -f)'{--from-dev,-D}'[use contents of given .deb archives as patterns]' \
+  '(--ignore-case -i)'{--ignore-case,-i}'[ignore case]' \
+  '(--regexp -x)'{--regexp,-x}'[regular expression]' \
+  '(-V --version)'{-V,--version}'[version]' \
+  '(-a --architecture)'{-a,--architecture}'[architecture]:architecture:_deb_architectures' \
+  '(-s --sources-list)'{-s,--sources-list}'[source.list file]:file:_files' \
+  '(-l --package-only)'{-l,--package-only}'[only display package name]' \
+  '(-N --non-interactive)'{-N,--non-interactive}'[skip schemes requiring user input]' \
+  '(-F --fixed-string)'{-F,--fixed-string}'[do not expand search pattern]' \
+  '(-y --dummy)'{-y,--dummy}'[run in dummy mode]' \
+  '(-)'{-h,--help}'[display help screen]' \
+  '1: :->cmds' \
+  '*: :->args' && ret=0
+
+case $state in
+  cmds)
+    cmds=(
+      'update:resynchronize package contents'
+      {find,search}:'search in which package file is included'
+      {list,show}:'list contents of a package'
+      'purge:remove all Contents-<ARCH>.gz files in cache directory'
+    )
+    _describe -t commands 'apt-list command' cmds
+  ;;
+  args)
+    case $line[1] in
+      search|find)
+	if (( $#opt_args[(I)(-D|--from-deb)] )); then
+	  _wanted files expl 'debian package' _files -g '*.deb(-.)'
+	elif (( $#opt_args[(I)(-f|--from-file)] )); then
+          _files
+	else
+	  _message -e patterns "pattern"
+	fi
+      ;;
+      list|show)
+	_deb_packages avail
       ;;
-      args)
-        case $line[1] in
-            search)
-                _message "pattern"
-            ;;
-            list|show)
-               _deb_packages avail 
-            ;;
-            update|purge)
-                # do nothing
-            ;;
-            *)
-                _message "command $line[1] not available"
-            ;;
-        esac
+      update|purge)
+	# do nothing
+      ;;
+      *)
+	_message "command $line[1] not available"
       ;;
     esac
+  ;;
+esac && ret=0
 
-}
-
-_apt-file "$@"
+return ret
diff --git a/Completion/Debian/Command/_dak b/Completion/Debian/Command/_dak
index 840fc00..086196c 100644
--- a/Completion/Debian/Command/_dak
+++ b/Completion/Debian/Command/_dak
@@ -1,31 +1,26 @@
 #compdef dak
 
-local curcontext="$curcontext" state line expl cmd args ret=1
-typeset -A opt_args
+local expl cmd args ret=1
 
-_arguments -C \
-    '1: :->cmd' \
-    '*:: :->args' && ret=0
-
-if (( ! $+_dak_cmds )); then
+if (( CURRENT == 2 )); then
+  if (( ! $+_dak_cmds )); then
     typeset -gH _dak_cmds
     _dak_cmds=(${${${(f)${"$(_call_program dak dak --help)"#*Availa#ble commands:}}#[^a-z] ##}%%[ 	]*})
-fi
+  fi
 
-if [[ $state != 'args' ]]; then
-    _describe -t subcommand 'subcommand' _dak_cmds
-    return 0
+  _describe -t subcommands 'subcommand' _dak_cmds
+  return
 fi
 
-cmd="$words[1]"
-curcontext="${curcontext%:*:*}:dak-$cmd:"
+cmd="$words[2]"
+local curcontext="${curcontext%:*:*}:dak-$cmd:"
 
 args=( '(-)'{--help,-h}'[show help message]' )
 
 case $cmd in
 (ls)
     args+=(
-  '(-a --architecture)'{-a,--architecture=}':arch:_values -s , "architecture list" source all alpha amd64 arm hppa hurd-i386 i386 ia64 mips mipsel'
+  '(-a --architecture)'{-a,--architecture=}':arch:_sequence _deb_architectures -a "all source"'
   '(-b --binary-type)'{-b,--binary-type=}':type:(deb udeb)'
   '(-c --component)'{-c,--component=}':component:_values -s , "component list" main contrib non-free'
   '(-g --greaterorequal)'{-g,--greaterorequal}
@@ -70,7 +65,7 @@ case $cmd in
     ;;
 (rm)
     args+=(
-  '(-a --architecture)'{-a,--architecture=}':arch:_values -s , "architecture list" source all alpha amd64 arm hppa hurd-i386 i386 ia64 mips mipsel'
+  '(-a --architecture)'{-a,--architecture=}':arch:_sequence _deb_architectures -a "all source"'
   '(-b --binary)'{-b,--binary}'[remove binaries only]'
   '(-c --component)'{-c,--component=}':component:_values -s , "component list" main contrib non-free'
   '(-C --carbon-copy)'{-C,--carbon-copy=}':cc address:_email_addresses'
@@ -96,7 +91,7 @@ case $cmd in
 
 (make-suite-file-list)
     args+=(
-   '(-a --architecture)'{-a,--architecture=}':arch:_values -s , "architecture list" source all alpha amd64 arm hppa hurd-i386 i386 ia64 mips mipsel'
+   '(-a --architecture)'{-a,--architecture=}':arch:_sequence _deb_architectures -a "all source"'
   '(-c --component)'{-c,--component=}':component:_values -s , "component list" main contrib non-free'
   '(-n --no-delete)'{-n,--no-delete}'[do not delete older versions]'
   '(-s --suite)'{-s,--suite=}':suite:_values -s , "suite list" oldstable stable testing unstable experimental'
@@ -239,10 +234,10 @@ case $cmd in
     ;;
 
     (*)
-    _files
+      args+=( '*: :_default' )
     ;;
 
 esac
 
 _arguments -s "$args[@]" && ret=0
-return $ret
+return ret
diff --git a/Completion/Debian/Command/_dpkg-buildpackage b/Completion/Debian/Command/_dpkg-buildpackage
index d6f5c5f..b0eea57 100644
--- a/Completion/Debian/Command/_dpkg-buildpackage
+++ b/Completion/Debian/Command/_dpkg-buildpackage
@@ -5,7 +5,7 @@ _arguments \
   '-B[binary-only build, no source or arch-indep binaries]' \
   '-S[source-only build, no binaries]' \
   '-s-:source generation:((i\:default a\:force\ inclusion\ of\ original\ source d\:force\ exclusion\ of\ original\ source))' \
-  '-a-:architecture:(alpha amd64 arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
+  '-a-:architecture:_deb_architectures' \
   '-v-:version:' \
   '-C-:changes description:_files' \
   '-m-:maintainer address:_email_addresses' \
diff --git a/Completion/Debian/Command/_dpkg-repack b/Completion/Debian/Command/_dpkg-repack
index 5d625a5..37f8005 100644
--- a/Completion/Debian/Command/_dpkg-repack
+++ b/Completion/Debian/Command/_dpkg-repack
@@ -2,6 +2,6 @@
 
 _arguments \
   '--root=[take package from filesystem rooted on <dir>]:root dir:_files -/' \
-  '--arch=[force the package to be built for architecture <arch>]:architecture:(alpha amd64 arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
+  '--arch=[force the package to be built for specified architecture]:architecture:_deb_architectures' \
   '--generate[generate build directory but do not build deb]' \
   '*:package:_deb_packages xinstalled'
diff --git a/Completion/Debian/Command/_lintian b/Completion/Debian/Command/_lintian
index 554be45..773e7a1 100644
--- a/Completion/Debian/Command/_lintian
+++ b/Completion/Debian/Command/_lintian
@@ -31,7 +31,7 @@ case "$service" in
       '--archivedir:archive directory:_files -/' \
       '--dist:distribution:(woody sarge sid)' \
       '--section:release:(main contrib non-free)' \
-      '--arch:architecture:(alpha arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
+      '--arch:architecture:_deb_architectures' \
       '--root:root directory:_files -/' \
       '(-a --all)'{-a,--all}'[check all packages in the distribution]' \
       '(-b --binary)'{-b,--binary}'[the following packages are binary]' \
diff --git a/Completion/Debian/Command/_madison b/Completion/Debian/Command/_madison
index fc4821e..445b79a 100644
--- a/Completion/Debian/Command/_madison
+++ b/Completion/Debian/Command/_madison
@@ -1,7 +1,7 @@
 #compdef madison rmadison
 
 _arguments \
-  '(-a --architecture)'{-a,--architecture=}':arch:_values -s , "architecture list" source all alpha arm hppa hurd-i386 i386 ia64 mips mipsel' \
+  '(-a --architecture)'{-a,--architecture=}':arch:_sequence _deb_architectures -a "all source" -' \
   '(-b --binary)'{-b,--binary-type=}':type:(deb udeb)' \
   '(-c --component)'{-c,--component=}':component:_values -s , "component list" main contrib non-free' \
   '(-g --greaterorequal)'{-g,--greaterorequal} \
diff --git a/Completion/Debian/Command/_pbuilder b/Completion/Debian/Command/_pbuilder
index 7811d56..9322d03 100644
--- a/Completion/Debian/Command/_pbuilder
+++ b/Completion/Debian/Command/_pbuilder
@@ -14,8 +14,8 @@ else
     '--buildresult:location:_files -/' \
     '--mirror:URL:_urls' \
     '--othermirror:URL:_urls' \
-    '--distribution:suite:(breezy dapper edgy etch feisty gutsy hardy hoary intrepid jaunty karmic lenny lucid potato sarge sid squeeze warty woody' \
-    '--architecture:architecture:(alpha amd64 armel hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
+    '--distribution:suite:(breezy dapper edgy etch feisty gutsy hardy hoary intrepid jaunty jessie karmic lenny lucid potato sarge sid squeeze warty woody' \
+    '--architecture:architecture:i_deb_architectures' \
     '--components:component:(main contrib non-free)' \
     '--override-config' \
     '--hookdir:location:_files -/' \
diff --git a/Completion/Debian/Command/_reprepro b/Completion/Debian/Command/_reprepro
index 44ed154..d1e124e 100644
--- a/Completion/Debian/Command/_reprepro
+++ b/Completion/Debian/Command/_reprepro
@@ -1,10 +1,10 @@
 #compdef reprepro
 
-local context state line distfile
+local curcontext="$curcontext" state line expl distfile ret=1
 typeset -A opt_args
 local -a codenames
 
-_arguments \
+_arguments -C \
   '(-h --help)'{-h,--help}'[display help]' \
   '*'{-v,-V,--verbose}'[be more verbose]' \
   '--silent[be less verbose]' \
@@ -17,7 +17,7 @@ _arguments \
   '--listdir:list dir:_files -/' \
   '--methoddir:method dir:_files -/' \
   '(-C --component)'{-C,--component}':component:(component1 component2)' \
-  '(-A --architecture)'{-A,--architecture}':architecture:(amd64 sparc)' \
+  '(-A --architecture)'{-A,--architecture}':architecture:_sequence -s "|" _deb_architectures -' \
   '(-T --type)'{-T,--type}':file type:(dsc deb udeb)' \
   '(-S --section)'{-S,--section}':section:(section1 section2)' \
   '(-P --priority)'{-P,--priority}':priority:(high low)' \
@@ -40,12 +40,11 @@ _arguments \
     rereference dumpreferences dumpunreferenced deleteunreferenced
     reoverride dumptracks retrack removealltracks removetrack tidytracks
     copy clearvanished gensnapshot rerunnotifiers)' \
-  '*::subcmd:->subcmd' && return 0
+  '*::subcmd:->subcmd' && ret=0
 
 case "$state" in
-    (subcmd)
-
-  case "$words[1]" in
+  subcmd)
+    case "$words[1]" in
       (export|update|iteratedupdate|checkupdate|predelete|pull|checkpull|check)
         if [[ -n "$opt_args[--confdir]" ]]; then
 	  distfile=${opt_args[--confdir]}/distributions
@@ -60,11 +59,13 @@ case "$state" in
 	fi
 
         codenames=($(awk '/^[Cc][Oo][Dd][Ee][Nn][Aa][Mm][Ee]: / {$1="";print}' "$distfile"))
-      	_wanted -V 'codenames' expl 'codename' compadd -a codenames
-	;;
+	_wanted -V 'codenames' expl 'codename' compadd -a codenames && ret=0
+      ;;
       (*)
-    	_files
-    	;;
-  esac
+	_files && ret=0
+      ;;
+    esac
   ;;
 esac
+
+return ret
diff --git a/Completion/Debian/Command/_svn-buildpackage b/Completion/Debian/Command/_svn-buildpackage
index 0b4d501..e0f9258 100644
--- a/Completion/Debian/Command/_svn-buildpackage
+++ b/Completion/Debian/Command/_svn-buildpackage
@@ -28,8 +28,8 @@ _arguments \
   '-B[binary-only build, no source or arch-indep binaries]' \
   '-S[source-only build, no binaries]' \
   '-s-:source generation:((i\:default a\:force\ inclusion\ of\ original\ source d\:force\ exclusion\ of\ original\ source))' \
-  '-a-:architecture:(alpha amd64 arm hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc)' \
-  '-v-:version:' \
+  '-a-:architecture:_deb_architectures' \
+  '-v-:version' \
   '-C-:changes description:_files' \
   '-m-:maintainer address:_email_addresses' \
   '-e-:maintainer address:_email_addresses' \
diff --git a/Completion/Debian/Type/_deb_architectures b/Completion/Debian/Type/_deb_architectures
new file mode 100644
index 0000000..79f2c6a
--- /dev/null
+++ b/Completion/Debian/Type/_deb_architectures
@@ -0,0 +1,9 @@
+#autoload
+
+local extra
+zparseopts -E -D -a extra a:
+
+_description architectures expl 'architecture'
+compadd "$@" "$expl[@]" alpha amd64 arm64 armel armhf hppa hurd-i386 i386 ia64 \
+    kfreebsd-amd64 kfreebsd-i386 m68k mips mipsel powerpc powerpcspe ppc64 \
+    ppc64el s390x sh4 sparc sparc64 x32 ${=extra[2]}



Messages sorted by: Reverse Date, Date, Thread, Author