about summary refs log tree commit diff
path: root/Completion/Unix/Type/_arch_namespace
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/Type/_arch_namespace
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/Type/_arch_namespace')
-rw-r--r--Completion/Unix/Type/_arch_namespace105
1 files changed, 105 insertions, 0 deletions
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 "$@"