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

Re: caching mechanism and Re: PATCH Completion for _yum



On 22 Nov, I wrote:
> One thing I noticed was that the use of the cache mechanism seemed
> broken. This is code that has been copied from elsewhere but appears
> widely in other functions.
>
> We seem to either have:
>   if _cache_invalid svn-cmds || ! _retrieve_cache svn-cmds; then
>  - seems logical: regenerate if cache is invalid or we fail to restore it
> or:
>   if ( [[ ${+_dput_cfhosts} -eq 0 ]] || _cache_invalid dputhosts ) && ! _retrieve_cache dputhosts; then
>  - which makes no sense to me.

I went through correcting other cases of this particular broken logic.
Substituting instead this logic:
  if (( ! $+_dput_cfhosts[1] )) && { _cache_invalid dputhosts ||
      ! _retrieve_cache dputhosts }

Whether we want to be keeping caches also in a global variable is a
different question but I've renamed them to all have _cache as a prefix.

I'm also not keen on the functions setting a zstyle for the
default cache policy. Couldn't the default just be a parameter
to _cache_invalid? Some of the style lookups eschewed $curcontext so it
is not making it easier to use right.

The naming convention for these policy functions also doesn't help
people to get the sense of the return status right. How about something
like _finkpkgs_cache_stale instead of _finkpkgs_caching_policy?

Patch also has a few other minor tweaks/fixes. _path_commands wasn't
and still doesn't work for all common man implementations. The Debian
uninstalled package bit must have predated the :| operator because it
was using fgrep. :| is noticably faster.

Oliver

diff --git a/Completion/Darwin/Command/_fink b/Completion/Darwin/Command/_fink
index 04a067e..6f73224 100644
--- a/Completion/Darwin/Command/_fink
+++ b/Completion/Darwin/Command/_fink
@@ -2,36 +2,37 @@
 
 _fink_get_packages_with_cache(){
   local cache_policy
-  zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
+  zstyle -s ":completion:${curcontext}:packages" cache-policy cache_policy
   if [[ -z "$cache_policy" ]]; then
-    zstyle ":completion:${curcontext}:" cache-policy _finkpkgs_caching_policy
+    zstyle ":completion:${curcontext}:packages" cache-policy _finkpkgs_caching_policy
   fi
 
-  typeset -g -a _fink_pkgs
+  typeset -g -a _cache_fink_pkgs
   local expl
 
-  if ( (( #_fink_pkgs == 0 )) || _cache_invalid finkpkgs) \
-       && ! _retrieve_cache finkpkgs; then
-    _fink_pkgs=(${(f)"$(
+  if (( ! $+_cache_fink_pkgs[1] )) && { _cache_invalid fink-pkgs ||
+      ! _retrieve_cache fink-pkgs }
+  then
+    _cache_fink_pkgs=(${(f)"$(
       command fink list --tab \
       | command grep -v '\[virtual package\]' \
       | command sed 's/^   / n /' \
       | command cut -f1,2
     )"})
-    _store_cache finkpkgs _fink_pkgs
+    _store_cache fink-pkgs _cache_fink_pkgs
   fi
 
   if (( # > 0 )); then
     local i
     for i in "$@"; do
       case "$i" in
-        -i) packages+=(${${(M)_fink_pkgs:#?i?*}#*	}) ;;
-        -o) packages+=(${${(M)_fink_pkgs:#(i)*}#*	}) ;;
-        -n) packages+=(${${(M)_fink_pkgs:# n *}#*	}) ;;
+        -i) packages+=(${${(M)_cache_fink_pkgs:#?i?*}#*	}) ;;
+        -o) packages+=(${${(M)_cache_fink_pkgs:#(i)*}#*	}) ;;
+        -n) packages+=(${${(M)_cache_fink_pkgs:# n *}#*	}) ;;
       esac
     done
   else
-    packages=(${_fink_pkgs#*	})
+    packages=( ${_cache_fink_pkgs#*	} )
   fi
 }
 
@@ -47,7 +48,7 @@ _fink_get_packages_without_cache(){
 
 _fink_get_packages(){
   # variable packages will be set
-  if zstyle -t ":completion:${curcontext}:" use-cache; then
+  if zstyle -t ":completion:${curcontext}:packages" use-cache; then
     _fink_get_packages_with_cache "$@"
   else
     _fink_get_packages_without_cache "$@"
diff --git a/Completion/Darwin/Type/_mac_applications b/Completion/Darwin/Type/_mac_applications
index 51fa0c4..d1982a3 100644
--- a/Completion/Darwin/Type/_mac_applications
+++ b/Completion/Darwin/Type/_mac_applications
@@ -3,5 +3,5 @@
 _retrieve_mac_apps
 
 local expl
-_wanted commands expl 'Mac OS X application' \
-    compadd "$@" - "${(@)${_mac_apps[@]:t}%.app}"
+_wanted commands expl 'macOS application' \
+    compadd "$@" - "${(@)${_cache_mac_apps[@]:t}%.app}"
diff --git a/Completion/Darwin/Type/_mac_files_for_application b/Completion/Darwin/Type/_mac_files_for_application
index 299d8ff..f4e36c0 100644
--- a/Completion/Darwin/Type/_mac_files_for_application
+++ b/Completion/Darwin/Type/_mac_files_for_application
@@ -39,7 +39,7 @@ _mac_files_for_application() {
 
   local app_path
   _retrieve_mac_apps
-  app_path="${_mac_apps[(r)*/$1(|.app)]:-$1}"
+  app_path="${_cache_mac_apps[(r)*/$1(|.app)]:-$1}"
 
   local -a glob_patterns
   glob_patterns=()
diff --git a/Completion/Darwin/Type/_retrieve_mac_apps b/Completion/Darwin/Type/_retrieve_mac_apps
index f24d36c..6fdfa32 100644
--- a/Completion/Darwin/Type/_retrieve_mac_apps
+++ b/Completion/Darwin/Type/_retrieve_mac_apps
@@ -1,6 +1,6 @@
 #autoload
 
-# Find paths of applications and preserve them into _mac_apps.
+# Find paths of applications and preserve them in _cache_mac_apps.
 # Used by _mac_applications and _mac_files_for_application.
 
 _mac_apps_caching_policy () {
@@ -14,14 +14,14 @@ _mac_apps_caching_policy () {
 # _mac_apps_*_retrieve
 # 
 # Get search applications from directories specified in app_dir_root.
-# Paths to applications are stored in _mac_apps.
+# Paths to applications are stored in _cache_mac_apps.
 
 _mac_apps_spotlight_retrieve () {
   typeset mdfind_query="kMDItemContentType == 'com.apple.application-*'"
 
   for i in ${app_dir_root}; do
-    _mac_apps+=(${(f)"$(_call_program command \
-        mdfind -onlyin ${(q)i} ${(q)mdfind_query})"})
+    _cache_mac_apps+=( ${(f)"$(_call_program command \
+        mdfind -onlyin ${(q)i} ${(q)mdfind_query})"} )
   done
 }
 
@@ -43,7 +43,7 @@ _mac_apps_old_retrieve () {
 
   if ! zstyle -t ":completion:${curcontext}:commands" ignore-bundle; then
     app_result=( ${^app_dir}*/Contents/(MacOS|MacOSClassic)(N) )
-    _mac_apps+=( ${app_result[@]%/Contents/MacOS*} )
+    _cache_mac_apps+=( ${app_result[@]%/Contents/MacOS*} )
   fi
 
   # Get single file applications
@@ -54,24 +54,24 @@ _mac_apps_old_retrieve () {
     envvars="$(builtin typeset -x)"
     nargs=$(( $(command sysctl -n kern.argmax) - $#envvars - 2048 ))
     app_result="$(zargs --max-chars $nargs ${app_cand[@]} -- grep -l APPL)"
-    _mac_apps+=( ${${(f)app_result}%/..namedfork/rsrc} )
+    _cache_mac_apps+=( ${${(f)app_result}%/..namedfork/rsrc} )
   fi
 }
 
 
 _retrieve_mac_apps() {
   local cache_policy
-  zstyle -s ":completion:*:*:$service:*" cache-policy cache_policy
+  zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
   if [[ -z "$cache_policy" ]]; then
-    zstyle ":completion:*:*:$service:*" cache-policy _mac_apps_caching_policy
+    zstyle ":completion:${curcontext}:" cache-policy _mac_apps_caching_policy
   fi
 
-  if ( (( ${#_mac_apps} == 0 )) || _cache_invalid Mac_applications ) \
-        && ! _retrieve_cache Mac_applications; then
-
+  if (( ! $+_cache_mac_apps[1] )) && { _cache_invalid mac-applications ||
+      ! _retrieve_cache mac-applications }
+  then
     # Get application search method
     typeset retrieve
-    if ! zstyle -s ":completion:*:*:${service}:commands" search-method retrieve
+    if ! zstyle -s ":completion:${curcontext}:commands" search-method retrieve
     then
       if [[ -d /.Spotlight-V100 ]]; then
         # / is indexed to use Spotlight
@@ -80,7 +80,7 @@ _retrieve_mac_apps() {
         # Fall back to the old way
         retrieve=_mac_apps_old_retrieve 
       fi
-      zstyle ":completion:*:*:${service}:commands" search-method $retrieve
+      zstyle ":completion:${curcontext}:commands" search-method $retrieve
     fi
 
     # Get root directories to search applications
@@ -96,10 +96,10 @@ _retrieve_mac_apps() {
       zstyle ":completion:*" application-path $app_dir_root
     fi
 
-    typeset -g -Ua _mac_apps
+    typeset -g -Ua _cache_mac_apps
     $retrieve
 
-    _store_cache Mac_applications _mac_apps
+    _store_cache mac-applications _cache_mac_apps
   fi
 }
 
diff --git a/Completion/Debian/Command/_dcut b/Completion/Debian/Command/_dcut
index fb1ac7e..28f0dd8 100644
--- a/Completion/Debian/Command/_dcut
+++ b/Completion/Debian/Command/_dcut
@@ -7,21 +7,23 @@
 # be offered. If host is given, the second argument should be completed as
 # command and if not, it should be completed as command specific option.
 
-function _dput_hosts() {
+_dput_hosts() {
   local expl
 
-  if ( [[ ${+_dput_cfhosts} -eq 0 ]] || _cache_invalid dputhosts ) && ! _retrieve_cache dputhosts; then
+  if (( ! $+_cache_dput_cfhosts[1] )) && { _cache_invalid dput-hosts ||
+      ! _retrieve_cache dput-hosts }
+  then
     local cmd
     if _pick_variant dputng="usage: dput" dput -H ; then
-      cmd=(dirt hosts)
+      cmd=( dirt hosts )
     else
-      cmd=(dput -H)
+      cmd=( dput -H )
     fi
-     _dput_cfhosts=(${${(M)${(f)"$($cmd)"}:#*=>*}/ =>*/})
-    _store_cache dputhosts _dput_cfhosts
+    _cache_dput_cfhosts=( ${${(M)${(f)"$(_call_program dput-hosts $cmd)"}:#*=>*}/ =>*/} )
+    _store_cache dput-hosts _cache_dput_cfhosts
   fi
 
-  _wanted dputhosts expl 'target host' compadd -a _dput_cfhosts
+  _wanted dput-hosts expl 'target host' compadd -a _cache_dput_cfhosts
 }
 
 function _dcut_commands() {
diff --git a/Completion/Debian/Command/_dput b/Completion/Debian/Command/_dput
index bf6c2ba..d7765d3 100644
--- a/Completion/Debian/Command/_dput
+++ b/Completion/Debian/Command/_dput
@@ -44,18 +44,20 @@ _dput() {
 _dput_hosts() {
   local expl
 
-  if ( [[ ${+_dput_cfhosts} -eq 0 ]] || _cache_invalid dputhosts ) && ! _retrieve_cache dputhosts; then
+  if (( ! $+_cache_dput_cfhosts[1] )) && { _cache_invalid dput-hosts ||
+      ! _retrieve_cache dput-hosts }
+  then
     local cmd
     if _pick_variant dputng="usage: dput" dput -H ; then
-      cmd=(dirt hosts)
+      cmd=( dirt hosts )
     else
-      cmd=(dput -H)
+      cmd=( dput -H )
     fi
-     _dput_cfhosts=(${${(M)${(f)"$($cmd)"}:#*=>*}/ =>*/})
-    _store_cache dputhosts _dput_cfhosts
+    _cache_dput_cfhosts=( ${${(M)${(f)"$(_call_program dput-hosts $cmd)"}:#*=>*}/ =>*/} )
+    _store_cache dput-hosts _cache_dput_cfhosts
   fi
 
-  _wanted dputhosts expl 'target host' compadd -a _dput_cfhosts
+  _wanted dput-hosts expl 'target host' compadd -a _cache_dput_cfhosts
 }
 
 _dput "$@"
diff --git a/Completion/Debian/Type/_deb_packages b/Completion/Debian/Type/_deb_packages
index bdc0cb0..ae77968 100644
--- a/Completion/Debian/Type/_deb_packages
+++ b/Completion/Debian/Type/_deb_packages
@@ -3,96 +3,89 @@
 # Usage: _deb_packages expl...  (installed|deinstalled|xinstalled|held|uninstalled|avail|available|source)
 
 _deb_packages_update_avail () {
-  if ( [[ ${+_deb_packages_cache_avail} -eq 0 ]] ||
-      _cache_invalid DEBS_avail ) && ! _retrieve_cache DEBS_avail;
+  cachevar=_cache_deb_packages_avail
+  if (( ! $+_cache_deb_packages_avail[1] )) &&
+      { _cache_invalid debs-avail || ! _retrieve_cache debs-avail }
   then
-    _deb_packages_cache_avail=(
-      ${(f)"$(apt-cache --generate pkgnames 2>/dev/null)"}
+    _cache_deb_packages_avail=(
+      ${(f)"$(_call_program packages apt-cache --generate pkgnames)"}
     )
-
-    _store_cache DEBS_avail _deb_packages_cache_avail
+    _store_cache debs-avail $cachevar
   fi
-  cachevar=_deb_packages_cache_avail
 }
 
 _deb_packages_update_installed () {
-  if ( [[ ${+_deb_packages_cache_installed} -eq 0 ]] ||
-      _cache_invalid DEBS_installed ) && ! _retrieve_cache DEBS_installed;
+  cachevar=_cache_deb_packages_installed
+  if (( ! $+_cache_deb_packages_installed[1] )) &&
+      { _cache_invalid debs-installed || ! _retrieve_cache debs-installed }
   then
-    _deb_packages_cache_installed=()
-    dpkg --get-selections | while read package state ; do
-        [[ $state = (install|hold) ]] && _deb_packages_cache_installed+=$package
-    done
-    _store_cache DEBS_installed _deb_packages_cache_installed
+    _cache_deb_packages_installed=(
+      ${${(M)${(f)"$(_call_program packages dpkg --get-selections)"}:#*([^e]install|hold)}%%[[:blank:]]*}
+    )
+    _store_cache debs-installed $cachevar
   fi
-  cachevar=_deb_packages_cache_installed
 }
 
 _deb_packages_update_held () {
-  if ( [[ ${+_deb_packages_cache_held} -eq 0 ]] ||
-      _cache_invalid DEBS_held ) && ! _retrieve_cache DEBS_held;
+  cachevar=_cache_deb_packages_held
+  if (( ! $+_cache_deb_packages_held[1] )) && { _cache_invalid debs-held ||
+      ! _retrieve_cache debs-held }
   then
-    _deb_packages_cache_held=()
-    dpkg --get-selections | while read package state ; do
-        [[ $state = hold ]] && _deb_packages_cache_held+=$package
-    done
-    _store_cache DEBS_held _deb_packages_cache_held
+    _cache_deb_packages_held=(
+      ${${(M)${(f)"$(_call_program packages dpkg --get-selections)"}:#*hold}%%[[:blank:]]*}
+    )
+    _store_cache debs-held $cachevar
   fi
-  cachevar=_deb_packages_cache_held
 }
 
 _deb_packages_update_deinstalled () {
-  if ( [[ ${+_deb_packages_cache_deinstalled} -eq 0 ]] ||
-      _cache_invalid DEBS_deinstalled ) && ! _retrieve_cache DEBS_deinstalled;
+  cachevar=_cache_deb_packages_deinstalled
+  if (( ! $+_cache_deb_packages_deinstalled[1] )) &&
+      { _cache_invalid debs-deinstalled || ! _retrieve_cache debs-deinstalled }
   then
-    _deb_packages_cache_deinstalled=()
-    dpkg --get-selections | while read package state ; do
-        [[ $state = deinstall ]] && _deb_packages_cache_deinstalled+=$package
-    done
-    _store_cache DEBS_deinstalled _deb_packages_cache_deinstalled
+    _cache_deb_packages_deinstalled=(
+      ${${(M)${(f)"$(_call_program packages dpkg --get-selections)"}:#*deinstalled}%%[[:blank:]]*}
+    )
+    _store_cache debs-deinstalled $cachevar
   fi
-  cachevar=_deb_packages_cache_deinstalled
 }
 
 _deb_packages_update_xinstalled () {
-  if ( [[ ${+_deb_packages_cache_xinstalled} -eq 0 ]] ||
-      _cache_invalid DEBS_xinstalled ) && ! _retrieve_cache DEBS_xinstalled;
+  cachevar=_cache_deb_packages_xinstalled
+  if (( ! $+_cache_deb_packages_xinstalled[1] )) &&
+      { _cache_invalid debs-xinstalled || ! _retrieve_cache debs-xinstalled }
   then
-    _deb_packages_cache_xinstalled=()
-    dpkg --get-selections | while read package state ; do
-        _deb_packages_cache_xinstalled+=$package
-    done
-    _store_cache DEBS_xinstalled _deb_packages_cache_xinstalled
+    _cache_deb_packages_xinstalled=(
+      ${${(f)"$(_call_program packages dpkg --get-selections)"}%%[[:blank:]]*}
+    )
+    _store_cache debs-xinstalled $cachevar
   fi
-  cachevar=_deb_packages_cache_xinstalled
 }
 
 _deb_packages_update_uninstalled () {
-  _deb_packages_update_avail
-  _deb_packages_update_installed
-  if (( ! $+_deb_packages_cache_uninstalled )); then
-    # Package lists too large to efficiently diff with zsh expansion
-    _deb_packages_cache_uninstalled=(
-      $( print -l $_deb_packages_cache_avail |
-         fgrep -xvf =(print -l $_deb_packages_cache_installed) )
+  if (( ! $+_cache_deb_packages_uninstalled )); then
+    _deb_packages_update_avail
+    _deb_packages_update_installed
+    _cache_deb_packages_uninstalled=(
+      ${_cache_deb_packages_avail:|_cache_deb_packages_installed}
     )
   fi
-  cachevar=_deb_packages_cache_uninstalled
+  cachevar=_cache_deb_packages_uninstalled
 }
 
 _deb_packages_update_source () {
-  if ( [[ ${+_deb_packages_cache_source} -eq 0 ]] ||
-      _cache_invalid DEBS_source ) && ! _retrieve_cache DEBS_source;
+  cachevar=_cache_deb_packages_source
+  if (( ! $+_cache_deb_packages_source[1] )) &&
+      { _cache_invalid debs-source || ! _retrieve_cache debs-source }
   then
-    _deb_packages_cache_source=(
+    _cache_deb_packages_source=(
       # requires apt >= 1.1.8
       # if dpkg --compare-versions "$(dpkg-query --show --showformat '${Version}\n' apt)" '>=' '1.1.8' ; then ...; else ...; fi
       ${(f)"$(/usr/lib/apt/apt-helper cat-file $(apt-get indextargets --format '$(FILENAME)' 'Created-By: Sources' 2>/dev/null) 2>/dev/null | sed -ne 's/^Package: //p' | uniq)"}
     )
 
-    _store_cache DEBS_source _deb_packages_cache_source
+    _store_cache debs-source $cachevar
   fi
-  cachevar=_deb_packages_cache_source
 }
 
 _deb_packages () {
diff --git a/Completion/Redhat/Command/_rpm b/Completion/Redhat/Command/_rpm
index b24213e..8031dbf 100644
--- a/Completion/Redhat/Command/_rpm
+++ b/Completion/Redhat/Command/_rpm
@@ -234,16 +234,16 @@ _rpm () {
 	  ${${(M)${(f)"$(_call_programs targets rpm --showrc)"}:#compatible archs*}##*: } && ret=0
       ;;
     groups)
-      if ( (( ! $+_rpm_groups )) || _cache_invalid rpm-groups ) &&
-	  ! _retrieve_cache rpm-groups
+      if (( ! $+_cache_rpm_groups[1] )) && { _cache_invalid rpm-groups ||
+	  ! _retrieve_cache rpm-groups }
       then
-	typeset -gaU _rpm_groups
-	_rpm_groups=(
-	    ${(f)"$(_call_program groups rpm -qa --queryformat '%\{group}\\n' 2>/dev/null)"}
+	typeset -gaU _cache_rpm_groups
+	_cache_rpm_groups=(
+	  ${(f)"$(_call_program groups rpm -qa --queryformat '%\{group}\\n')"}
 	)
-	_store_cache RPM-groups _rpm_groups
+	_store_cache rpm-groups _cache_rpm_groups
       fi
-      _wanted groups expl 'group' _multi_parts / _rpm_groups && ret=0
+      _wanted groups expl 'group' _multi_parts / _cache_rpm_groups && ret=0
     ;;
     package_or_file)
       state=package_file
@@ -256,14 +256,14 @@ _rpm () {
       fi
       ;;
     package)
-      if ( [[ ${+_rpms} -eq 0 ]] || _cache_invalid RPMs ) &&
-	 ! _retrieve_cache RPMs;
+      if (( ! $+_cache_rpms[1] )) && { _cache_invalid rpm-packages ||
+	  ! _retrieve_cache rpm-packages }
       then
-	_rpms=( $(_call_program packages rpm -qa 2>/dev/null) )
-	_store_cache RPMs _rpms
+	_cache_rpms=( $(_call_program packages rpm -qa) )
+	_store_cache rpm-packages _cache_rpms
       fi
       _wanted packages expl 'package' \
-	  compadd -M 'r:|-=* r:|=*' - "$_rpms[@]" && ret=0
+	  compadd -M 'r:|-=* r:|=*' -a _cache_rpms && ret=0
       ;;
     spec_files)
       _wanted specfiles expl 'spec file' \
@@ -316,9 +316,9 @@ _rpm () {
 
 # set a sensible default caching policy
 local update_policy
-zstyle -s ":completion:*:*:rpm:*" cache-policy update_policy
+zstyle -s ":completion:${curcontext}:" cache-policy update_policy
 if [[ -z "$update_policy" ]]; then
-  zstyle ":completion:*:*:rpm:*" cache-policy _rpms_caching_policy
+  zstyle ":completion:${curcontext}:" cache-policy _rpms_caching_policy
 fi
 
 _rpms_caching_policy () {
diff --git a/Completion/Solaris/Command/_pkg5 b/Completion/Solaris/Command/_pkg5
index bcd4e3d..b427788 100644
--- a/Completion/Solaris/Command/_pkg5
+++ b/Completion/Solaris/Command/_pkg5
@@ -1,49 +1,53 @@
 #compdef pkg
 
 _pkg5_pkgs() {
-	local cache_policy cache_id=pkg5_installed_pkgs:$HOST:${pkg5_root//\//+}
-	typeset -a -g _pkg5_installed_pkgs
+	local cache_policy cache_id=pkg5-installed-pkgs:$HOST:${pkg5_root//\//+}
+	typeset -a -g _cache_pkg5_installed_pkgs
 
-	zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
+	zstyle -s ":completion:${curcontext}:packages" cache-policy cache_policy
 	if [[ -z "$cache_policy" ]]; then
-		zstyle ":completion:${curcontext}:" cache-policy _pkg5_installed_caching_policy
+		zstyle ":completion:${curcontext}:packages" cache-policy _pkg5_installed_caching_policy
 	fi
 
-	if ( [[ $#_pkg5_installed_pkgs -eq 0 ]] || _cache_invalid $cache_id ) && ! _retrieve_cache $cache_id; then
-		_pkg5_installed_pkgs=( $(
+	if (( ! $+_cache_pkg5_installed_pkgs[1] )) && { _cache_invalid $cache_id ||
+	    ! _retrieve_cache $cache_id }
+	then
+		_cache_pkg5_installed_pkgs=( $(
 			pkg -R $pkg5_root list -H | while read pkg junk; do
 				pkga=( ${(s:/:)pkg} )
 				for i in {1..$#pkga}; do
 					print ${(j:/:)${pkga[$i,-1]}}
 				done
 			done) )
-		_store_cache $cache_id _pkg5_installed_pkgs
+		_store_cache $cache_id _cache_pkg5_installed_pkgs
 	fi
 
-	compadd "$@" - ${_pkg5_installed_pkgs}
+	_wanted packages expl package compadd "$@" -a - _cache_pkg5_installed_pkgs
 }
 
 _pkg5_pkgs_a() {
-	local cache_policy cache_id=pkg5_known_pkgs:$HOST:${pkg5_root//\//+}
-	typeset -a -g _pkg5_known_pkgs
+	local cache_policy cache_id=pkg5-known-pkgs:$HOST:${pkg5_root//\//+}
+	typeset -a -g _cache_pkg5_known_pkgs
 
-	zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
+	zstyle -s ":completion:${curcontext}:packages" cache-policy cache_policy
 	if [[ -z "$cache_policy" ]]; then
-		zstyle ":completion:${curcontext}:" cache-policy _pkg5_known_caching_policy
+		zstyle ":completion:${curcontext}:packages" cache-policy _pkg5_known_caching_policy
 	fi
 
-	if ( [[ $#_pkg5_known_pkgs -eq 0 ]] || _cache_invalid $cache_id ) && ! _retrieve_cache $cache_id; then
-		_pkg5_known_pkgs=( $(
+	if (( ! $+_cache_pkg5_known_pkgs[1] )) && { _cache_invalid $cache_id ||
+	    ! _retrieve_cache $cache_id }
+	then
+		_cache_pkg5_known_pkgs=( $(
 			pkg -R $pkg5_root list -aH --no-refresh | while read pkg junk; do
 				pkga=( ${(s:/:)pkg} )
 				for i in {1..$#pkga}; do
 					print ${(j:/:)${pkga[$i,-1]}}
 				done
 			done) )
-		_store_cache $cache_id _pkg5_known_pkgs
+		_store_cache $cache_id _cache_pkg5_known_pkgs
 	fi
 
-	compadd "$@" - ${_pkg5_known_pkgs}
+	_wanted packages expl package compadd "$@" -a - _cache_pkg5_known_pkgs
 }
 
 _pkg5_avoided_pkgs() {
@@ -130,7 +134,7 @@ _pkg5() {
 			return
 		fi
 		service="$words[1]"
-		curcontext="${curcontext%:*}=$service:"
+		curcontext="${curcontext%:*}-$service:"
 	fi
 
 	pkg5_root=${${${opt_args[-R]}:-$PKG_IMAGE}:-/}
diff --git a/Completion/Solaris/Type/_svcs_fmri b/Completion/Solaris/Type/_svcs_fmri
index 80d3516..19d460d 100644
--- a/Completion/Solaris/Type/_svcs_fmri
+++ b/Completion/Solaris/Type/_svcs_fmri
@@ -3,12 +3,12 @@
 _svcs_fmri() {
 	local type="$argv[$#]"
 	local fmri_abbrevs m i
-	typeset -a -g _smf_fmris
+	typeset -a -g _cache_smf_fmris
 
 	local update_policy
-	zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+	zstyle -s ":completion:${curcontext}:fmri" cache-policy update_policy
 	if [[ -z "$update_policy" ]]; then
-		zstyle ":completion:${curcontext}:" cache-policy _smf_caching_policy
+		zstyle ":completion:${curcontext}:fmri" cache-policy _smf_caching_policy
 	fi
 	# The cache really must be per-host
 	local cache_id=smf_fmri:$HOST
@@ -22,14 +22,15 @@ _svcs_fmri() {
 		# Grab all FMRIs that have a word beginning with $PREFIX,
 		# making sure not to return the portion of the FMRI before
 		# $PREFIX.  Use the cache if it exists and the user wants to.
-		if ( [[ $#_smf_fmris -eq 0 ]] || _cache_invalid $cache_id ) \
-			&& ! _retrieve_cache $cache_id; then
-			_smf_fmris=( ${(f)"$(svcs -a -H -o fmri)"} )
-			_store_cache $cache_id _smf_fmris
+		if (( ! $+_cache_smf_fmris[1] )) && { _cache_invalid $cache_id ||
+		    ! _retrieve_cache $cache_id }
+	        then
+			_cache_smf_fmris=( ${(f)"$(_call_program fmris svcs -a -H -o fmri)"} )
+			_store_cache $cache_id _cache_smf_fmris
 		fi
 		# Each element of the array is removed which doesn't match
 		# (^|.*/)$PREFIX.*
-		fmri_abbrevs=( ${(M)_smf_fmris:#((#s)|*[/:])$PREFIX*} )
+		fmri_abbrevs=( ${(M)_cache_smf_fmris:#((#s)|*[/:])$PREFIX*} )
 
 		# Go through the remaining elements and remove the characters
 		# in front of $PREFIX.
diff --git a/Completion/Unix/Command/_bogofilter b/Completion/Unix/Command/_bogofilter
index ff36e83..7a98395 100644
--- a/Completion/Unix/Command/_bogofilter
+++ b/Completion/Unix/Command/_bogofilter
@@ -49,20 +49,23 @@ _bogoutil() {
 	"($_bogoutil_actions)"{-V,--version}'[version]' \
   	'*:tokens:->tokens' && ret=0
 
-  zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+  zstyle -s ":completion:${curcontext}:tokens" cache-policy update_policy
   if [[ -z "$update_policy" ]]; then
-    zstyle ":completion:${curcontext}:" cache-policy _bogoutil_caching_policy
+    zstyle ":completion:${curcontext}:tokens" cache-policy _bogoutil_caching_policy
   fi
 
   case $state in
-  	(tokens)
-  	if ( [[ -z "$bogotokens" ]] || _cache_invalid bogotokens ) &&
-  	  ! _retrieve_cache bogotokens; then
-          bogotokens=(${${(f)"$(_call_program bogotokens bogoutil -d ~/.bogofilter/wordlist.db -c 50)"}%% *})
-  	  _store_cache bogotokens bogotokens
-  	fi
-          _wanted tokens expl "token" compadd -a bogotokens && ret=0
-  	;;
+    (tokens)
+      if (( ! $+_cache_bogotokens[1] )) && { _cache_invalid bogotokens ||
+	  ! _retrieve_cache bogotokens }
+      then
+	_cache_bogotokens=(
+	  ${${(f)"$(_call_program bogotokens bogoutil -d ~/.bogofilter/wordlist.db -c 50)"}%% *}
+	)
+	_store_cache bogotokens _cache_bogotokens
+      fi
+      _wanted tokens expl "token" compadd -a _cache_bogotokens && ret=0
+    ;;
   esac
 
   return ret
diff --git a/Completion/Unix/Type/_path_commands b/Completion/Unix/Type/_path_commands
index 66795ae..2e1976a 100644
--- a/Completion/Unix/Type/_path_commands
+++ b/Completion/Unix/Type/_path_commands
@@ -3,61 +3,63 @@
 (( $+functions[_path_commands_caching_policy] )) ||
 _path_commands_caching_policy() {
 
-local file
-local -a oldp dbfiles
+local file ret=0
+local -a oldp dbdirs
 
 # rebuild if cache is more than a week old
 oldp=( "$1"(Nmw+1) )
 (( $#oldp )) && return 0
 
-dbfiles=(/usr/share/man/index.(bt|db|dir|pag)(N) \
-  /usr/man/index.(bt|db|dir|pag)(N) \
-  /var/cache/man/index.(bt|db|dir|pag)(N) \
-  /var/catman/index.(bt|db|dir|pag)(N) \
-  /usr/share/man/*/whatis(N))
-
-for file in $dbfiles; do
+dbdirs=( $manpath /usr/share/man /usr/man /var/cache/man /var/catman{,/man} /usr/share/man/(^man*)(N) )
+for file in $dbdirs/(windex|whatis|index.(bt|db|dir|pag))(N); do
   [[ $file -nt $1 ]] && return 0
+  ret=1
 done
 
-return 1
+return ret
 }
 
 _call_whatis() { 
-  case "$(whatis --version)" in
-  ("whatis from "*)
-    local -A args
-    zparseopts -D -A args s: r:
-    apropos "${args[-r]:-"$@"}" | fgrep "($args[-s]"
-    ;;
-  (*) whatis "$@";;
+  case "$OSTYPE:$(whatis --version)" in
+  (solaris*)
+    apropos -s 1 | tr -s $'\t ' ' ' | cut -d ' ' -f 1,3-
+  ;;
+  (freebsd*) ;&
+  (*:"whatis from "*)
+    apropos '.*' | grep "([16]"
+  ;;
+  (*)
+    whatis -s 1 -r '.*'
+    whatis -s 6 -r '.*'
+  ;;
   esac
 }
 
 _path_commands() {
 local need_desc expl ret=1
 
-if zstyle -t ":completion:${curcontext}:" extra-verbose; then
+if zstyle -t ":completion:${curcontext}:commands" extra-verbose; then
   local update_policy first
-  if [[ $+_command_descriptions -eq 0 ]]; then
+  if (( ! $+_cache_command_descriptions )); then
     first=yes
-    typeset -A -g _command_descriptions
+    typeset -A -g _cache_command_descriptions
   fi
-  zstyle -s ":completion:${curcontext}:" cache-policy update_policy
-  [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" \
+  zstyle -s ":completion:${curcontext}:commands" cache-policy update_policy
+  [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:commands" \
     cache-policy _path_commands_caching_policy
-  if ( [[ -n $first ]] || _cache_invalid command-descriptions ) && \
-    ! _retrieve_cache command-descriptions; then
+  if [[ -n $first ]] && { _cache_invalid command-descriptions ||
+      ! _retrieve_cache command-descriptions }
+  then
     local line
-    for line in "${(f)$(_call_program command-descriptions _call_whatis -s 1 -r .\\\*\; _call_whatis -s 6 -r .\\\* 2>/dev/null)}"; do
+    for line in "${(f)$(_call_program command-descriptions _call_whatis)}"; do
       [[ -n ${line:#(#b)([^ ]#) #\([^ ]#\)( #\[[^ ]#\]|)[ -]#(*)} ]] && continue;
       [[ -z $match[1] || -z $match[3] || -z ${${match[1]}:#*:*} ]] && continue;
-      _command_descriptions[$match[1]]=$match[3]
+      _cache_command_descriptions[$match[1]]=$match[3]
     done
-    _store_cache command-descriptions _command_descriptions
+    _store_cache command-descriptions _cache_command_descriptions
   fi
 
-  (( $#_command_descriptions )) && need_desc=yes
+  (( $+_cache_command_descriptions )) && need_desc=yes
 fi
 
 if [[ -n $need_desc ]]; then
@@ -65,7 +67,7 @@ if [[ -n $need_desc ]]; then
   local desc cmd sep
   compadd "$@" -O matches -k commands
   for cmd in $matches; do
-    desc=$_command_descriptions[$cmd]
+    desc=$_cache_command_descriptions[$cmd]
     if [[ -z $desc ]]; then
       cmds+=$cmd
     else
@@ -73,7 +75,7 @@ if [[ -n $need_desc ]]; then
       descs+="$cmd:$desc"
     fi
   done
-  zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
+  zstyle -s ":completion:${curcontext}:commands" list-separator sep || sep=--
   zformat -a descs " $sep " $descs
   descs=("${(@r:COLUMNS-1:)descs}")
   _wanted commands expl 'external command' \
@@ -98,7 +100,7 @@ if [[ -o path_dirs ]]; then
   fi
 fi
 
-return $ret
+return ret
 }
 
 _path_commands "$@"
diff --git a/Completion/Unix/Type/_perl_modules b/Completion/Unix/Type/_perl_modules
index d27a7f7..0ecce8d 100644
--- a/Completion/Unix/Type/_perl_modules
+++ b/Completion/Unix/Type/_perl_modules
@@ -39,9 +39,9 @@ _perl_modules () {
   local update_policy sufpat=".pm" with_pod
   local restrict_hierarchy=''
   local -i strip_perl_prefix
-  zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+  zstyle -s ":completion:${curcontext}:modules" cache-policy update_policy
   if [[ -z "$update_policy" ]]; then
-    zstyle ":completion:${curcontext}:" cache-policy \
+    zstyle ":completion:${curcontext}:modules" cache-policy \
       _perl_modules_caching_policy
   fi
 
@@ -71,11 +71,11 @@ _perl_modules () {
     perl_modules=_unknown_perl_modules$with_pod
   fi
 
-  if ( [[ ${(P)+perl_modules} -eq 0 ]] || _cache_invalid ${perl_modules#_} ) &&
-     ! _retrieve_cache ${perl_modules#_};
+  if [[ ${(P)+perl_modules} -eq 0 ]] && { _cache_invalid ${perl_modules#_} ||
+      ! _retrieve_cache ${perl_modules#_} }
   then
     if zstyle -t ":completion:${curcontext}:modules" try-to-use-pminst &&
-       (( ${+commands[pminst]} ));
+        (( ${+commands[pminst]} ))
     then
       set -A $perl_modules $(pminst)
     else
diff --git a/Completion/Unix/Type/_python_modules b/Completion/Unix/Type/_python_modules
index e82f8ef..9404bfe 100644
--- a/Completion/Unix/Type/_python_modules
+++ b/Completion/Unix/Type/_python_modules
@@ -16,27 +16,26 @@ _python_modules () {
     (*)       python="python" ;;
   esac
   local cache_id=${${python//[^[:alnum:]]/_}#_}_modules
-  local array_name=_${cache_id}
+  local array_name=_cache_${cache_id}
 
-  zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+  zstyle -s ":completion:${curcontext}:modules" cache-policy update_policy
   [[ -z "$update_policy" ]] && \
-    zstyle ":completion:${curcontext}:" \
+    zstyle ":completion:${curcontext}:modules" \
       cache-policy _python_module_caching_policy
 
-  if ( [[ ${(P)+array_name} -eq 0 ]] || _cache_invalid $cache_id ) &&
-      ! _retrieve_cache $cache_id; then
-
-   local script='import pkgutil
+  if [[ ${(P)+array_name} -eq 0 ]] && { _cache_invalid $cache_id ||
+      ! _retrieve_cache $cache_id }
+  then
+    local script='import pkgutil
 for importer, name, ispkg in pkgutil.iter_modules(): print(name)'
 
     typeset -agU $array_name
-    set -A $array_name \
-      $(_call_program modules $python -c ${(q)script} 2>/dev/null)
+    set -A $array_name $(_call_program modules $python -c ${(q)script})
 
     _store_cache $cache_id $array_name
   fi
 
-  _wanted modules expl module compadd "$@" -a -- $array_name
+  _wanted modules expl module compadd "$@" -a - $array_name
 }
 
 _python_modules "$@"
diff --git a/Completion/openSUSE/Command/_zypper b/Completion/openSUSE/Command/_zypper
index 25a32c3..cd3f411 100644
--- a/Completion/openSUSE/Command/_zypper
+++ b/Completion/openSUSE/Command/_zypper
@@ -15,24 +15,20 @@
 #
 # Main dispatcher
 
-function _zypper_caching_policy () {
-    # rebuild if zsh's cache is older than zypper's
-    if test /var/cache/zypp/raw -nt "$1"; then
-        return 0
-    else
-        return 1
-    fi
+_zypper_caching_policy() {
+    # rebuild if cache is absent or older than zypper's
+    [[ ! /var/cache/zypp/raw -ot "$1" ]]
 }
 
 _zypper() {
     typeset -A opt_args
-    local context curcontext="$curcontext" state line
+    local curcontext="$curcontext"
 
     if (( CURRENT > 2 )) && [[ ${words[2]} != "help" ]]; then
         # Remember the subcommand name
         local cmd=${words[2]}
         # Set the context for the subcommand.
-        curcontext="${curcontext%:*:*}:zypper-subcommand"
+        curcontext="${curcontext%:*:*}:zypper-$cmd"
         # Narrow the range of words we are looking at to exclude `zypper'
         (( CURRENT-- ))
         shift words
@@ -65,26 +61,25 @@ _zypper() {
 _all_repos() {
     local -a repos
     repos=( $(zypper -q lr | tail -n +3 | cut -d'|' -f 2) )
-    _describe -t repos 'Available repositories' repos && return
+    _describe -t repos 'available repository' repos && return
 }
 
 _enabled_repos() {
     repos=( $(zypper -x lr | grep 'enabled="1"' | cut -d\" -f 2) )
-    _describe -t repos 'Available repositories' repos && return
+    _describe -t repos 'available repository' repos && return
 }
 
 _disabled_repos() {
     repos=( $(zypper -x lr | grep 'enabled="0"' | cut -d\" -f 2) )
-    _describe -t repos 'Available repositories' repos && return
+    _describe -t repos 'available repository' repos && return
 }
 
 _zypper_cmd_do() {
     typeset -A opt_args
-    local context state line
+    local expl
     local hline
     local -a cmdlist
     local tag=0
-    local curcontext="$curcontext"
 
     zstyle ":completion:${curcontext}:" use-cache on
     zstyle ":completion:${curcontext}:" cache-policy _zypper_caching_policy
@@ -107,7 +102,7 @@ _zypper_cmd_do() {
         case ${words[CURRENT - 1]} in
             --from)
                 repos=( $(zypper -x lr | grep 'enabled="1"' | cut -d\" -f 2) )
-                _describe -t repos 'Available repositories' repos && return
+                _describe -t repos 'available repository' repos && return
                ;;
             (--enable|-e)
                 case $cmd in
@@ -128,7 +123,7 @@ _zypper_cmd_do() {
                 case $cmd in
                     (if|info|se|search|in|install) 
                         types=( pattern srcpackage package patch )
-                        _describe -t types 'Package types' types && return
+                        _describe -t types 'package type' types && return
                     ;;
                 esac
                 ;;
@@ -142,9 +137,8 @@ _zypper_cmd_do() {
                 _all_repos
                 ;;
             (in|install)
-                local expl
                 _description files expl 'RPM files' 
-                _files "$expl[@]" -g '*.(#i)rpm(.)'
+                _files "$expl[@]" -g '*.(#i)rpm(-.)'
                 ;;
         esac
         
@@ -152,27 +146,29 @@ _zypper_cmd_do() {
         if [[ ${words[CURRENT]} =~ "^[0-9a-zA-Z]" ]] ; then
           local -a pkglist
 
-          if ( [[ ${+_zypp_all_raw} -eq 0 ]] || _cache_invalid ZYPPER_ALL_RAW ) && ! _retrieve_cache ZYPPER_ALL_RAW;
+	  if (( ! $+_cache_zypp_all_raw[1] )) && { _cache_invalid zypper-all-raw ||
+	      ! _retrieve_cache zypper-all-raw }
           then
-              _zypp_all_raw=$(zypper -x -q se | grep '<solvable' | cut -d \" -f 2,4)
-              _zypp_all=( $(echo $_zypp_all_raw | grep 'installed' | cut -d\" -f 2) )
-              _zypp_not_installed=( $(echo $_zypp_all_raw | grep 'not-installed' | cut -d\" -f 2 ) )
-              _zypp_installed=( $(echo $_zypp_all_raw | grep '^installed' | cut -d\" -f 2 ) )
-              _store_cache ZYPPER_ALL_RAW _zypp_all_raw _zypp_all _zypp_not_installed _zypp_installed
+              _cache_zypp_all_raw=$(zypper -x -q se | grep '<solvable' | cut -d \" -f 2,4)
+              _cache_zypp_all=( $(echo $_zypp_all_raw | grep 'installed' | cut -d\" -f 2) )
+              _cache_zypp_not_installed=( $(echo $_zypp_all_raw | grep 'not-installed' | cut -d\" -f 2 ) )
+              _cache_zypp_installed=( $(echo $_zypp_all_raw | grep '^installed' | cut -d\" -f 2 ) )
+              _store_cache zypper-all-raw _cache_zypp_all_raw _cache_zypp_all \
+		  _cache_zypp_not_installed _cache_zypp_installed
           fi
 
           case $cmd in
               (in|install)
-                  pkglist=( $_zypp_not_installed )
-                  compadd $pkglist && return
+                  pkglist=( $_cache_zypp_not_installed )
+                  _wanted packaged expl package compadd -a pkglist
                   ;;
               (rm|remove|up|update)
-                  pkglist=( $_zypp_installed )
-                  compadd $pkglist && return
+                  pkglist=( $_cache_zypp_installed )
+                  compadd -a pkglist
                   ;;
               (if|info|se|search)
-                  pkglist=( $_zypp_all )
-                  compadd $pkglist && return
+                  pkglist=( $_cache_zypp_all )
+                  compadd -a pkglist
                   ;;
           esac
         fi



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