about summary refs log tree commit diff
path: root/Completion/Unix/Type
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2005-04-16 20:24:48 +0000
committerClint Adams <clint@users.sourceforge.net>2005-04-16 20:24:48 +0000
commitde553ca7db878dfb94cce02a1a9190a7c735a6b0 (patch)
tree0fa06cd24d661624624e11036710a9f83b367ab1 /Completion/Unix/Type
parentf82136ac94a7bc9e2d50223bbccd04a307a5a6d2 (diff)
downloadzsh-de553ca7db878dfb94cce02a1a9190a7c735a6b0.tar.gz
zsh-de553ca7db878dfb94cce02a1a9190a7c735a6b0.tar.xz
zsh-de553ca7db878dfb94cce02a1a9190a7c735a6b0.zip
* 21147: factor out some common code from _tla and _baz, and fix some
   breakage from 21075.
Diffstat (limited to 'Completion/Unix/Type')
-rw-r--r--Completion/Unix/Type/_arch_archives14
-rw-r--r--Completion/Unix/Type/_arch_namespace105
2 files changed, 119 insertions, 0 deletions
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 "$@"