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

Re: PATCH: make _deb_packages handle -J



In article <19991226220500.A842@xxxxxxxx>,
  Clint Adams <schizo@xxxxxxxxxx> writes:

> At some point _dpkg started passing '-J -default-' to _deb_packages,
> and _deb_packages didn't like it.  Since this is intended as a temporary
> solution, the option is not being passed along to compadd.

It's because there is no space between colon and _deb_packages in _dpkg.

> The result is that _apt and _dpkg will both work with _deb_packages.

I modified _deb_packages to take expl arguments at first and a command
at last.

Index: Completion/Debian/_apt
===================================================================
RCS file: /projects/zsh/zsh/Completion/Debian/_apt,v
retrieving revision 1.1.1.16
diff -u -r1.1.1.16 _apt
--- Completion/Debian/_apt	1999/12/10 14:47:58	1.1.1.16
+++ Completion/Debian/_apt	1999/12/27 21:03:24
@@ -375,14 +375,14 @@
     -- \
     /$'update\0'/ \| \
     /$'upgrade\0'/ \| \
-    /$'install\0'/ /$'[^\0]#\0'/ :'_deb_packages uninstalled "$expl_packages[@]" || _deb_packages installed "$expl_packages[@]" ' \# \| \
-    /$'remove\0'/ /$'[^\0]#\0'/ :'_deb_packages installed "$expl_packages[@]"' \# \| \
+    /$'install\0'/ /$'[^\0]#\0'/ :'_deb_packages "$expl_packages[@]" uninstalled || _deb_packages "$expl_packages[@]" installed' \# \| \
+    /$'remove\0'/ /$'[^\0]#\0'/ :'_deb_packages "$expl_packages[@]" installed' \# \| \
     /$'dist-upgrade\0'/ \| \
     /$'dselect-upgrade\0'/ \| \
     /$'clean\0'/ \| \
     /$'autoclean\0'/ \| \
     /$'check\0'/ \| \
-    /$'source\0'/ /$'[^\0]#\0'/ :'_deb_packages avail "$expl_packages[@]"' \# \| \
+    /$'source\0'/ /$'[^\0]#\0'/ :'_deb_packages "$expl_packages[@]" avail' \# \| \
     /$'help\0/' \| \
     /"[]"/	:'_tags actions && compadd "$expl_action[@]" update upgrade install remove dist-upgrade dselect-upgrade clean autoclean check source help'
 
@@ -413,14 +413,14 @@
     /$'help\0'/ \| \
     /$'add\0'/ /$'[^\0]#\0'/ :'_files' \# \| \
     /$'gencaches\0'/ \| \
-    /$'showpkg\0'/ /$'[^\0]#\0'/ :'_deb_packages avail "$expl_packages[@]"' \# \| \
+    /$'showpkg\0'/ /$'[^\0]#\0'/ :'_deb_packages "$expl_packages[@]" avail' \# \| \
     /$'stats\0'=$status[4]/ \| \
     /$'dump\0'/ \| \
     /$'dumpavail\0'/ \| \
     /$'unmet\0'/ \| \
     /$'check\0'/ \| \
     /$'search\0'/ \| \
-    /$'show\0'/ /$'[^\0]#\0'/ :'_deb_packages avail "$expl_packages[@]"' \# \| \
+    /$'show\0'/ /$'[^\0]#\0'/ :'_deb_packages "$expl_packages[@]" avail' \# \| \
     /$'depends\0'/ \| \
     /"[]"/ :'_tags actions && compadd "$expl_action[@]" help add gencaches showpkg stats dump dumpavail unmet check search show depends'
 
Index: Completion/Debian/_deb_packages
===================================================================
RCS file: /projects/zsh/zsh/Completion/Debian/_deb_packages,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 _deb_packages
--- Completion/Debian/_deb_packages	1999/12/27 06:19:34	1.1.1.4
+++ Completion/Debian/_deb_packages	1999/12/27 21:03:24
@@ -1,37 +1,49 @@
 #autoload
 
-local opt caopts
+# Usage: _deb_packages expl... avail|installed|uninstalled
 
-# Usage: _deb_packages installed|uninstalled|avail
-while getopts "J:" opt; do
-  case "$opt" in
-     J) caopts="-J $OPTARG"
-        shift 2			# presume that -J -default- are the first args
-        ;;
-  esac
-done
-
-if (( ! $+_deb_cache_dpkg_get_selections )); then
-  _deb_cache_dpkg_get_selections=(
-    ${(f)"$(dpkg --get-selections)"}
-  )
-  _deb_cache_avail=(
-    ${(f)"$(apt-cache dumpavail | awk '/^Package:/ { print $2 }')"}
-  )
-  _deb_cache_installed=(
-    ${${_deb_cache_dpkg_get_selections:#*deinstall}%%	*}
-  )
-  _deb_cache_uninstalled=(
-    ${_deb_cache_avail:#${(j:|:)~${_deb_cache_installed:q}}}
-  )
-fi
-
-local command="$1" expl
-shift
-
-_wanted packages expl packages &&
-    case "$command" in
-    installed) compadd "$@" - $_deb_cache_installed;;
-    uninstalled) compadd "$@" - $_deb_cache_uninstalled;;
-    avail) compadd "$@" - $_deb_cache_avail;;
-    esac
+_deb_packages_updage_avail () {
+  if (( ! $+_deb_packages_cache_uninstalled )); then
+    _deb_packages_cache_avail=(
+      ${(f)"$(apt-cache dumpavail | awk '/^Package:/ { print $2 }')"}
+    )
+  fi
+  cachevar=_deb_packages_cache_avail
+}
+
+_deb_packages_updage_installed () {
+  if (( ! $+_deb_packages_cache_installed )); then
+    _deb_packages_cache_installed=(
+      ${${${(f)"$(dpkg --get-selections)"}:#*deinstall}%%	*}
+    )
+  fi
+  cachevar=_deb_packages_cache_installed
+}
+
+_deb_packages_updage_uninstalled () {
+  _deb_packages_updage_avail
+  _deb_packages_updage_installed
+  if (( ! $+_deb_packages_cache_uninstalled )); then
+    _deb_packages_cache_uninstalled=(
+      ${_deb_packages_cache_avail:#${(j:|:)~${_deb_packages_cache_installed:q}}}
+    )
+  fi
+  cachevar=_deb_packages_cache_uninstalled
+}
+
+_deb_packages () {
+  local command="$argv[$#]" expl cachevar
+
+  [[ "$command" = (installed|uninstalled|avail) ]] || {
+    _message "_deb_packages:unknown command: $command"
+    return
+  }
+
+  expl=("${(@)argv[1,-2]}")
+
+  _deb_packages_updage_$command
+
+  _tags packages && compadd "$expl[@]" - "${(e):-"\${(@)$cachevar}"}"
+}
+
+_deb_packages "$@"
-- 
Tanaka Akira



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