diff --git a/src/_port b/src/_port index db39c1f..064928a 100644 --- a/src/_port +++ b/src/_port @@ -15,23 +15,6 @@ # # ------------------------------------------------------------------------------ -_port_select() { - if (( CURRENT == 3 )); then - _describe 'Port select options' select_options - elif (( CURRENT == 4 )); then - local select_group - select_group=() - for f in $port_prefix/etc/select/*; do - select_group+=$(basename $f) - done - _describe "Port select groups" select_group - elif [[ $CURRENT -eq 5 && $words[3] == '--set' ]]; then - local select_variants - select_variants=("${(f)$(port select --list $words[4] | sed -e '1 d' -e 's/^[ \t]*//' -e 's/ (active)$//')}") - _describe "Port select group $words[4] variants" select_variants - fi -} - _port() { # Variables for _argument typeset -A opt_args @@ -87,6 +70,12 @@ _port() { '*:extra:->extra' \ && return 0 + local cache_policy + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy _port_caching_policy + fi + case "$state" in extra) case "$words[2]" in @@ -103,22 +92,28 @@ _port() { _call_function - _port_select ;; contents|deactivate|setrequested|space|uninstall|unsetrequested) - # Cache the list of all ports. - if (( ! $+_installed_ports )); then - _installed_ports=$(_call_program path-installed "port installed | cut -d ' ' -f 3") + # Cache the list of installed ports. + if ( [[ ${+_port_installed_packages} -eq 0 ]] || _cache_invalid PORT_INSTALLED_PACKAGES ) && + ! _retrieve_cache PORT_INSTALLED_PACKAGES; + then + _port_installed_packages=( $(_call_program path-all "port echo all") ) + _store_cache PORT_INSTALLED_PACKAGES _port_installed_packages fi _alternative \ - "ports:Installed ports:($_installed_ports)" \ + "ports:Installed ports:($_port_installed_packages)" \ "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" ;; *) # Cache the list of all ports. - if (( ! $+_all_ports )); then - _all_ports=$(_call_program path-all "port echo all") + if ( [[ ${+_port_available_packages} -eq 0 ]] || _cache_invalid PORT_AVAILABLE_PACKAGES ) && + ! _retrieve_cache PORT_AVAILABLE_PACKAGES; + then + _port_available_packages=( $(_call_program path-all "port echo all") ) + _store_cache PORT_AVAILABLE_PACKAGES _port_available_packages fi _alternative \ - "ports:Available ports:($_all_ports)" \ + "ports:Available ports:($_port_available_packages)" \ "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" ;; @@ -127,4 +122,28 @@ _port() { esac } +_port_select() { + if (( CURRENT == 3 )); then + _describe 'Port select options' select_options + elif (( CURRENT == 4 )); then + local select_group + select_group=() + for f in $port_prefix/etc/select/*; do + select_group+=$(basename $f) + done + _describe "Port select groups" select_group + elif [[ $CURRENT -eq 5 && $words[3] == '--set' ]]; then + local select_variants + select_variants=("${(f)$(port select --list $words[4] | sed -e '1 d' -e 's/^[ \t]*//' -e 's/ (active)$//')}") + _describe "Port select group $words[4] variants" select_variants + fi +} + +_port_caching_policy() { + local reg_time comp_time + reg_time=$(stat -c '%Z' $port_prefix/var/macports/registry/registry.db) + comp_time=$(stat -c '%Z' $1) + return $(( reg_time < comp_time )) +} + _port "$@"