Moved port_select function to bottom

This commit is contained in:
Aljaž "g5pw" Srebrnič 2013-03-24 22:26:32 +01:00
parent 6483c0c3a1
commit 2224f3ae71
1 changed files with 43 additions and 24 deletions

View File

@ -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() { _port() {
# Variables for _argument # Variables for _argument
typeset -A opt_args typeset -A opt_args
@ -87,6 +70,12 @@ _port() {
'*:extra:->extra' \ '*:extra:->extra' \
&& return 0 && 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 case "$state" in
extra) extra)
case "$words[2]" in case "$words[2]" in
@ -103,22 +92,28 @@ _port() {
_call_function - _port_select _call_function - _port_select
;; ;;
contents|deactivate|setrequested|space|uninstall|unsetrequested) contents|deactivate|setrequested|space|uninstall|unsetrequested)
# Cache the list of all ports. # Cache the list of installed ports.
if (( ! $+_installed_ports )); then if ( [[ ${+_port_installed_packages} -eq 0 ]] || _cache_invalid PORT_INSTALLED_PACKAGES ) &&
_installed_ports=$(_call_program path-installed "port installed | cut -d ' ' -f 3") ! _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 fi
_alternative \ _alternative \
"ports:Installed ports:($_installed_ports)" \ "ports:Installed ports:($_port_installed_packages)" \
"pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
"pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
;; ;;
*) *)
# Cache the list of all ports. # Cache the list of all ports.
if (( ! $+_all_ports )); then if ( [[ ${+_port_available_packages} -eq 0 ]] || _cache_invalid PORT_AVAILABLE_PACKAGES ) &&
_all_ports=$(_call_program path-all "port echo all") ! _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 fi
_alternative \ _alternative \
"ports:Available ports:($_all_ports)" \ "ports:Available ports:($_port_available_packages)" \
"pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
"pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
;; ;;
@ -127,4 +122,28 @@ _port() {
esac 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 "$@" _port "$@"