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

PATCH: _tla, _baz, _arch_archives, _arch_namespace



This is an attempt to factor out some common code from _tla and _baz,
especially so it can be used by completion for axp.

Also, it reverts some breakage introduced by 21075.

Index: Completion/Unix/Command/_baz
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_baz,v
retrieving revision 1.4
diff -u -r1.4 _baz
--- Completion/Unix/Command/_baz	31 Mar 2005 13:44:07 -0000	1.4
+++ Completion/Unix/Command/_baz	16 Apr 2005 20:12:51 -0000
@@ -20,32 +20,20 @@
 fi
 
 # completion functions
-
 (( $+functions[_baz_archives] )) ||
-_baz_archives () {
-  local expl completions library name_arg='-n'
-  if [[ -n $argv[(r)--library] ]]; then
-    library='library-'
-    # remove parameter from $@ before calling compadd
-    argv[(r)--library]=()
-    name_arg=
-  fi
-  completions=($(_call_program baz $BAZ ${library:-}archives $name_arg))
-  _description -V archives expl "${library:-}archives"
-  compadd "$@" "$expl[@]" -- "$completions[@]"
-}
+_baz_archives () { _arch_archives baz "$@" }
 
 (( $+functions[_baz_categories] )) ||
-_baz_categories () { _baz_namespace 1 "$argv[@]" }
+_baz_categories () { _arch_namespace baz 1 "$argv[@]" }
 
 (( $+functions[_baz_branches] )) ||
-_baz_branches () {_baz_namespace 2 "$argv[@]" }
+_baz_branches () { _arch_namespace baz 2 "$argv[@]" }
 
 (( $+functions[_baz_versions] )) ||
-_baz_versions () { _baz_namespace 3 "$argv[@]" }
+_baz_versions () { _arch_namespace baz 3 "$argv[@]" }
 
 (( $+functions[_baz_revisions] )) ||
-_baz_revisions () { _baz_namespace 4 "$argv[@]" }
+_baz_revisions () { _arch_namespace baz 4 "$argv[@]" }
 
 (( $+functions[_baz_local_revisions] )) ||
 _baz_local_revisions () {
@@ -58,102 +46,6 @@
   # Should complete based on -A, -R, -d
 }
 
-(( $+functions[_baz_namespace] )) ||
-_baz_namespace () { #double as arch_namespace_categories
-# takes an integer argument specifying how many components:
-# 1: category
-# 2: branch
-# 3: version
-# 4: revision
-  local suffix expl archive=`$BAZ my-default-archive 2> /dev/null`
-  local trailing_dashes=0
-  [[ -n $argv[(r)--trailing-dashes] ]] && trailing_dashes=1
-  local library
-  [[ -n $argv[(r)--library] ]] && library='library-';
-  local exclude_library_revisions=0
-  [[ -n $argv[(r)--exclude-library-revisions] ]] && exclude_library_revisions=1
-
-  if [ $1 -gt 1 ] || (( trailing_dashes )); then
-    suffix=(-q -S --)
-  fi
-  if [[ $PREFIX = */* ]]; then
-    compset -P '*/'
-    archive=${IPREFIX%/*}
-    _description -V categories expl "${library:-}categories in $archive"
-    compadd $suffix "$expl[@]" `$BAZ ${library:-}categories $archive`
-  elif [ -z $IPREFIX ]; then
-    local index=$(( words[(i)-A] + 1 ))
-    (( index < CURRENT )) || index=$(( words[(i)--archive] + 1 ))
-    (( index < CURRENT )) && archive=$words[$index]
-
-    if [ $archive ]; then
-      _description -V categories expl "${library:-}categories in $archive"
-      compadd "$expl[@]" $suffix `$BAZ ${library:-}categories $archive`
-    fi
-
-    _baz_archives -S / ${library:+--library}
-  fi
-  if [ $archive ] && [ $1 -gt 1 ] && [[ $PREFIX != *@* ]] \
-     && [[ $PREFIX = *--* ]]; then
-  #this match could be better
-    _baz_namespace_branches $(($1 - 1))
-  fi
-}
-
-(( $+functions[_baz_namespace_branches] )) ||
-_baz_namespace_branches () {
-  local suffix expl
-  if [ $1 -gt 1 ] || (( $trailing_dashes )); then
-    suffix=(-q -S --)
-  fi
-  if [[ $IPREFIX != *-- ]]; then
-    compset -P 1 '*--'
-    local category=${IPREFIX%--}
-    _description -V branches expl "${library:-}branches"
-    compadd $suffix "$expl[@]" \
-      ${${(@)$($BAZ ${library:-}branches $archive/$category)}##*--}
-  fi
-  if [ $1 -gt 1 ] && [[ $IPREFIX = *-- ]] && [[ $PREFIX = *--* ]]; then
-    _baz_namespace_versions $(($1 - 1))
-  fi
-}
-
-(( $+functions[_baz_namespace_versions] )) ||
-_baz_namespace_versions () {
-  local suffix expl
-  if [ $1 -gt 1 ]; then
-    suffix=(-q -S --)
-  fi
-  if [[ $IPREFIX != *--*-- ]] || [[ $IPREFIX != */*--*-- ]]; then
-    compset -P 1 '*--'
-    local branch=${IPREFIX%--}
-    _description -V versions expl "${library:-}versions"
-    compadd $suffix "$expl[@]" \
-      ${${(@)$($BAZ ${library:-}versions $archive/$branch)}##*--}
-  fi
-  if [ $1 -gt 1 ] && [[ $IPREFIX = *--*-- ]] && ([[ $IPREFIX = */*--*-- ]] \
-    || [[ $PREFIX != */* ]]) && [[ $PREFIX = *--* ]]; then
-    _baz_namespace_revisions
-  fi
-}
-
-(( $+functions[_baz_namespace_revisions] )) ||
-_baz_namespace_revisions () {
-  local expl
-  if [[ $IPREFIX != *--*--*-- ]] || [[ $IPREFIX != */*--*--*-- ]]; then
-    compset -P 1 '*--'
-    local version=${IPREFIX%--}
-    _description -V revisions expl "${library:-}revisions"
-    local completions c
-    completions=(
-      ${${(@)$($BAZ ${library:-}revisions $archive/$version)}##*--}
-    )
-    (( exclude_library_revisions )) && \
-        foreach c ($($BAZ library-revisions $archive/$version)); do completions[(r)$c]=(); done
-    compadd "$expl[@]" -a completions
-  fi
-}
-
 (( $+functions[_baz_config] )) ||
 _baz_config () {
   local configdir root ret=1 n expl
Index: Completion/Unix/Command/_tla
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_tla,v
retrieving revision 1.4
diff -u -r1.4 _tla
--- Completion/Unix/Command/_tla	15 Jun 2004 20:33:45 -0000	1.4
+++ Completion/Unix/Command/_tla	16 Apr 2005 20:12:52 -0000
@@ -23,30 +23,19 @@
 # completion functions
 
 (( $+functions[_tla_archives] )) ||
-_tla_archives () {
-  local expl completions library name_arg='-n'
-  if [[ -n $argv[(r)--library] ]]; then
-    library='library-'
-    # remove parameter from $@ before calling compadd
-    argv[(r)--library]=()
-    name_arg=
-  fi
-  completions=($(_call_program tla $TLA ${library:-}archives $name_arg))
-  _description -V archives expl "${library:-}archives"
-  compadd "$@" "$expl[@]" -- "$completions[@]"
-}
+_tla_archives () { _arch_archives tla "$@" }
 
 (( $+functions[_tla_categories] )) ||
-_tla_categories () { _tla_namespace 1 "$argv[@]" }
+_tla_categories () { _arch_namespace tla 1 "$argv[@]" }
 
 (( $+functions[_tla_branches] )) ||
-_tla_branches () {_tla_namespace 2 "$argv[@]" }
+_tla_branches () {_arch_namespace tla 2 "$argv[@]" }
 
 (( $+functions[_tla_versions] )) ||
-_tla_versions () { _tla_namespace 3 "$argv[@]" }
+_tla_versions () { _arch_namespace tla 3 "$argv[@]" }
 
 (( $+functions[_tla_revisions] )) ||
-_tla_revisions () { _tla_namespace 4 "$argv[@]" }
+_tla_revisions () { _arch_namespace tla 4 "$argv[@]" }
 
 (( $+functions[_tla_local_revisions] )) ||
 _tla_local_revisions () {
@@ -59,102 +48,6 @@
   # Should complete based on -A, -R, -d
 }
 
-(( $+functions[_tla_namespace] )) ||
-_tla_namespace () { #double as arch_namespace_categories
-# takes an integer argument specifying how many components:
-# 1: category
-# 2: branch
-# 3: version
-# 4: revision
-  local suffix expl archive=`$TLA my-default-archive 2> /dev/null`
-  local trailing_dashes=0
-  [[ -n $argv[(r)--trailing-dashes] ]] && trailing_dashes=1
-  local library
-  [[ -n $argv[(r)--library] ]] && library='library-';
-  local exclude_library_revisions=0
-  [[ -n $argv[(r)--exclude-library-revisions] ]] && exclude_library_revisions=1
-
-  if [ $1 -gt 1 ] || (( trailing_dashes )); then
-    suffix=(-q -S --)
-  fi
-  if [[ $PREFIX = */* ]]; then
-    compset -P '*/'
-    archive=${IPREFIX%/*}
-    _description -V categories expl "${library:-}categories in $archive"
-    compadd $suffix "$expl[@]" `$TLA ${library:-}categories -A $archive`
-  elif [ -z $IPREFIX ]; then
-    local index=$(( words[(i)-A] + 1 ))
-    (( index < CURRENT )) || index=$(( words[(i)--archive] + 1 ))
-    (( index < CURRENT )) && archive=$words[$index]
-
-    if [ $archive ]; then
-      _description -V categories expl "${library:-}categories in $archive"
-      compadd "$expl[@]" $suffix `$TLA ${library:-}categories -A $archive`
-    fi
-
-    _tla_archives -S / ${library:+--library}
-  fi
-  if [ $archive ] && [ $1 -gt 1 ] && [[ $PREFIX != *@* ]] \
-     && [[ $PREFIX = *--* ]]; then
-  #this match could be better
-    _tla_namespace_branches $(($1 - 1))
-  fi
-}
-
-(( $+functions[_tla_namespace_branches] )) ||
-_tla_namespace_branches () {
-  local suffix expl
-  if [ $1 -gt 1 ] || (( $trailing_dashes )); then
-    suffix=(-q -S --)
-  fi
-  if [[ $IPREFIX != *-- ]]; then
-    compset -P 1 '*--'
-    local category=${IPREFIX%--}
-    _description -V branches expl "${library:-}branches"
-    compadd $suffix "$expl[@]" \
-      ${${(@)$($TLA ${library:-}branches -A $archive $category)}##*--}
-  fi
-  if [ $1 -gt 1 ] && [[ $IPREFIX = *-- ]] && [[ $PREFIX = *--* ]]; then
-    _tla_namespace_versions $(($1 - 1))
-  fi
-}
-
-(( $+functions[_tla_namespace_versions] )) ||
-_tla_namespace_versions () {
-  local suffix expl
-  if [ $1 -gt 1 ]; then
-    suffix=(-q -S --)
-  fi
-  if [[ $IPREFIX != *--*-- ]] || [[ $IPREFIX != */*--*-- ]]; then
-    compset -P 1 '*--'
-    local branch=${IPREFIX%--}
-    _description -V versions expl "${library:-}versions"
-    compadd $suffix "$expl[@]" \
-      ${${(@)$($TLA ${library:-}versions -A $archive $branch)}##*--}
-  fi
-  if [ $1 -gt 1 ] && [[ $IPREFIX = *--*-- ]] && ([[ $IPREFIX = */*--*-- ]] \
-    || [[ $PREFIX != */* ]]) && [[ $PREFIX = *--* ]]; then
-    _tla_namespace_revisions
-  fi
-}
-
-(( $+functions[_tla_namespace_revisions] )) ||
-_tla_namespace_revisions () {
-  local expl
-  if [[ $IPREFIX != *--*--*-- ]] || [[ $IPREFIX != */*--*--*-- ]]; then
-    compset -P 1 '*--'
-    local version=${IPREFIX%--}
-    _description -V revisions expl "${library:-}revisions"
-    local completions c
-    completions=(
-      ${${(@)$($TLA ${library:-}revisions -A $archive $version)}##*--}
-    )
-    (( exclude_library_revisions )) && \
-        foreach c ($($TLA library-revisions -A $archive $version)); do completions[(r)$c]=(); done
-    compadd "$expl[@]" -a completions
-  fi
-}
-
 (( $+functions[_tla_config] )) ||
 _tla_config () {
 
Index: Completion/Unix/Type/_arch_archives
===================================================================
RCS file: Completion/Unix/Type/_arch_archives
diff -N Completion/Unix/Type/_arch_archives
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Unix/Type/_arch_archives	16 Apr 2005 20:12:52 -0000
@@ -0,0 +1,14 @@
+#autoload
+
+local ARCHCMD="$1"
+shift
+local expl completions library name_arg='-n'
+if [[ -n $argv[(r)--library] ]]; then
+  library='library-'
+  # remove parameter from $@ before calling compadd
+  argv[(r)--library]=()
+  name_arg=
+fi
+completions=($(_call_program ${ARCHCMD} ${ARCHCMD} ${library:-}archives $name_arg))
+_description -V archives expl "${library:-}archives"
+compadd "$@" "$expl[@]" -- "$completions[@]"
Index: Completion/Unix/Type/_arch_namespace
===================================================================
RCS file: Completion/Unix/Type/_arch_namespace
diff -N Completion/Unix/Type/_arch_namespace
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Unix/Type/_arch_namespace	16 Apr 2005 20:12:52 -0000
@@ -0,0 +1,105 @@
+#autoload
+
+_arch_namespace () { #double as arch_namespace_categories
+  local ARCHCMD="$1"
+  shift
+# takes an integer argument specifying how many components:
+# 1: category
+# 2: branch
+# 3: version
+# 4: revision
+  local suffix expl archive=`$ARCHCMD my-default-archive 2> /dev/null`
+  local trailing_dashes=0
+  [[ -n $argv[(r)--trailing-dashes] ]] && trailing_dashes=1
+  local library
+  [[ -n $argv[(r)--library] ]] && library='library-';
+  local exclude_library_revisions=0
+  [[ -n $argv[(r)--exclude-library-revisions] ]] && exclude_library_revisions=1
+
+  if [ $1 -gt 1 ] || (( trailing_dashes )); then
+    suffix=(-q -S --)
+  fi
+  if [[ $PREFIX = */* ]]; then
+    compset -P '*/'
+    archive=${IPREFIX%/*}
+    _description -V categories expl "${library:-}categories in $archive"
+    compadd $suffix "$expl[@]" `$ARCHCMD ${library:-}categories $archive`
+  elif [ -z $IPREFIX ]; then
+    local index=$(( words[(i)-A] + 1 ))
+    (( index < CURRENT )) || index=$(( words[(i)--archive] + 1 ))
+    (( index < CURRENT )) && archive=$words[$index]
+
+    if [ $archive ]; then
+      _description -V categories expl "${library:-}categories in $archive"
+      compadd "$expl[@]" $suffix `$ARCHCMD ${library:-}categories $archive`
+    fi
+
+    _arch_archives "$ARCHCMD" -S / ${library:+--library}
+  fi
+  if [ $archive ] && [ $1 -gt 1 ] && [[ $PREFIX != *@* ]] \
+     && [[ $PREFIX = *--* ]]; then
+  #this match could be better
+    _arch_namespace_branches "$ARCHCMD" $(($1 - 1))
+  fi
+}
+
+(( $+functions[_arch_namespace_branches] )) ||
+_arch_namespace_branches () {
+  local ARCHCMD="$1"
+  shift
+  local suffix expl
+  if [ $1 -gt 1 ] || (( $trailing_dashes )); then
+    suffix=(-q -S --)
+  fi
+  if [[ $IPREFIX != *-- ]]; then
+    compset -P 1 '*--'
+    local category=${IPREFIX%--}
+    _description -V branches expl "${library:-}branches"
+    compadd $suffix "$expl[@]" \
+      ${${(@)$($ARCHCMD ${library:-}branches $category)}##*--}
+  fi
+  if [ $1 -gt 1 ] && [[ $IPREFIX = *-- ]] && [[ $PREFIX = *--* ]]; then
+    _arch_namespace_versions "${ARCHCMD}" $(($1 - 1))
+  fi
+}
+
+(( $+functions[_arch_namespace_versions] )) ||
+_arch_namespace_versions () {
+  local ARCHCMD="$1"
+  shift
+  local suffix expl
+  if [ $1 -gt 1 ]; then
+    suffix=(-q -S --)
+  fi
+  if [[ $IPREFIX != *--*-- ]] || [[ $IPREFIX != */*--*-- ]]; then
+    compset -P 1 '*--'
+    local branch=${IPREFIX%--}
+    _description -V versions expl "${library:-}versions"
+    compadd $suffix "$expl[@]" \
+      ${${(@)$($ARCHCMD ${library:-}versions $branch)}##*--}
+  fi
+  if [ $1 -gt 1 ] && [[ $IPREFIX = *--*-- ]] && ([[ $IPREFIX = */*--*-- ]] \
+    || [[ $PREFIX != */* ]]) && [[ $PREFIX = *--* ]]; then
+    _arch_namespace_revisions "${ARCHCMD}"
+  fi
+}
+
+(( $+functions[_arch_namespace_revisions] )) ||
+_arch_namespace_revisions () {
+  local ARCHCMD="$1"
+  local expl
+  if [[ $IPREFIX != *--*--*-- ]] || [[ $IPREFIX != */*--*--*-- ]]; then
+    compset -P 1 '*--'
+    local version=${IPREFIX%--}
+    _description -V revisions expl "${library:-}revisions"
+    local completions c
+    completions=(
+      ${${(@)$($ARCHCMD ${library:-}revisions $version)}##*--}
+    )
+    (( exclude_library_revisions )) && \
+        foreach c ($($ARCHCMD library-revisions $version)); do completions[(r)$c]=(); done
+    compadd "$expl[@]" -a completions
+  fi
+}
+
+_arch_namespace "$@"



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