about summary refs log tree commit diff
path: root/Completion/Unix
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2005-04-16 20:22:44 +0000
committerClint Adams <clint@users.sourceforge.net>2005-04-16 20:22:44 +0000
commit89f3361e60ec1da55f53a632a98d834b9f27e2cf (patch)
tree725f9b422aa3c92b24d3abb5743a7ed0c681784e /Completion/Unix
parentd6089cc8b17ed7d33850bb9075a9c6771fe120d6 (diff)
downloadzsh-89f3361e60ec1da55f53a632a98d834b9f27e2cf.tar.gz
zsh-89f3361e60ec1da55f53a632a98d834b9f27e2cf.tar.xz
zsh-89f3361e60ec1da55f53a632a98d834b9f27e2cf.zip
* 21147: factor out some common code from _tla and _baz, and fix some breakage
   from 21075.
Diffstat (limited to 'Completion/Unix')
-rw-r--r--Completion/Unix/Command/_baz118
-rw-r--r--Completion/Unix/Command/_tla117
-rw-r--r--Completion/Unix/Type/_arch_archives14
-rw-r--r--Completion/Unix/Type/_arch_namespace105
4 files changed, 129 insertions, 225 deletions
diff --git a/Completion/Unix/Command/_baz b/Completion/Unix/Command/_baz
index ceedc732d..c5a65437a 100644
--- a/Completion/Unix/Command/_baz
+++ b/Completion/Unix/Command/_baz
@@ -20,32 +20,20 @@ if zstyle -s ":completion:${curcontext}" hide-shortopts hide_short; then
 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 @@ _baz_local_revisions () {
   # 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
diff --git a/Completion/Unix/Command/_tla b/Completion/Unix/Command/_tla
index 0951cc749..876f9dcf3 100644
--- a/Completion/Unix/Command/_tla
+++ b/Completion/Unix/Command/_tla
@@ -23,30 +23,19 @@ fi
 # 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 @@ _tla_local_revisions () {
   # 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 () {
 
diff --git a/Completion/Unix/Type/_arch_archives b/Completion/Unix/Type/_arch_archives
new file mode 100644
index 000000000..9ffd7e3d3
--- /dev/null
+++ b/Completion/Unix/Type/_arch_archives
@@ -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[@]"
diff --git a/Completion/Unix/Type/_arch_namespace b/Completion/Unix/Type/_arch_namespace
new file mode 100644
index 000000000..171293887
--- /dev/null
+++ b/Completion/Unix/Type/_arch_namespace
@@ -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 "$@"