From de553ca7db878dfb94cce02a1a9190a7c735a6b0 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Sat, 16 Apr 2005 20:24:48 +0000 Subject: * 21147: factor out some common code from _tla and _baz, and fix some breakage from 21075. --- ChangeLog | 7 + Completion/Unix/Command/_baz | 118 +------ Completion/Unix/Command/_tla | 615 +++++++++++++++++++++++++++++++++++ Completion/Unix/Type/_arch_archives | 14 + Completion/Unix/Type/_arch_namespace | 105 ++++++ 5 files changed, 746 insertions(+), 113 deletions(-) create mode 100644 Completion/Unix/Command/_tla create mode 100644 Completion/Unix/Type/_arch_archives create mode 100644 Completion/Unix/Type/_arch_namespace diff --git a/ChangeLog b/ChangeLog index 9997f0409..9883dbeb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-04-16 Clint Adams + + * 21147: Completion/Unix/Command/_baz, + Completion/Unix/Command/_tla, Completion/Unix/Type/_arch_archives, + Completion/Unix/Type/_arch_namespace: factor out some common code + from _tla and _baz, and fix some breakage from 21075. + 2005-04-12 Clint Adams * 21135: Completion/Unix/Command/_screen: complete attached 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 new file mode 100644 index 000000000..876f9dcf3 --- /dev/null +++ b/Completion/Unix/Command/_tla @@ -0,0 +1,615 @@ +#compdef tla + +autoload is-at-least +local TLA=$words[1] +local tla_version +local hide_short + +# ask the user which version of tla this is +if ! zstyle -s ":completion:${curcontext}" tla-version tla_version; then + # ask tla instead + tla_version="${${$($TLA --version)#tla tla-}%% from regexps.com*}" + [[ $tla_version == *[a-zA-Z]* ]] && tla_version=1.3 # tla doesn't know +fi + +# test whether to hide short options from completion +if zstyle -s ":completion:${curcontext}" hide-shortopts hide_short; then + case $hide_short in + true|yes|on|1) hide_short='!' ;; + *) hide_short='' ;; + esac +fi + +# completion functions + +(( $+functions[_tla_archives] )) || +_tla_archives () { _arch_archives tla "$@" } + +(( $+functions[_tla_categories] )) || +_tla_categories () { _arch_namespace tla 1 "$argv[@]" } + +(( $+functions[_tla_branches] )) || +_tla_branches () {_arch_namespace tla 2 "$argv[@]" } + +(( $+functions[_tla_versions] )) || +_tla_versions () { _arch_namespace tla 3 "$argv[@]" } + +(( $+functions[_tla_revisions] )) || +_tla_revisions () { _arch_namespace tla 4 "$argv[@]" } + +(( $+functions[_tla_local_revisions] )) || +_tla_local_revisions () { + local expl1 expl2 tree_version=`$TLA tree-version` + _description -V applied-patches expl1 "patches from this version" + _description -V other-patches expl2 "patches from other versions" + compadd "$expl1[@]" `$TLA logs` + compadd "$expl2[@]" `$TLA logs --full $($TLA log-versions | grep -v $tree_version)` + # This is incredibly slow. + # Should complete based on -A, -R, -d +} + +(( $+functions[_tla_config] )) || +_tla_config () { + + # zsh 4.1.1+ is recommended; 4.0.6 gives the error below when doing + # tla build-config e + # _path_files:322: no matches found: configs//e/.(/) + # whereas 4.1.1 completes correctly + + local configdir root ret=1 n expl + + n=$opt_args[(i)(-d|--dir)] + [[ -n "$n" ]] && configdir=$opt_args[$n] + root="$(_call_program tla $TLA tree-root ${configdir} 2>&1)" + if (( $? )); then + _message -e messages "Error: $root" + return $ret + fi + + if [[ -d "$root/configs" ]]; then + configdir=("$root/configs") + _description files expl '%Bconfig file%b' + _files -W configdir "$expl[@]" && ret=0 + else + _message -e messages "No configs/ directory in tree whose root is $root" + fi + return $ret +} + +(( $+functions[_tla_limit] )) || +_tla_limit () { #presently only does push-mirror style limits + [[ $words[$CURRENT] == *@* ]] && return 1 + + local expl archive + archive=${words[(r)*@*]:-$($TLA my-default-archive 2> /dev/null)} + if [ $archive ]; then + + if [[ $PREFIX != *--* ]]; then + _description -V categories expl "categories in $archive" + compadd -q -S -- "$expl[@]" `$TLA categories -A $archive` + else + _tla_namespace_branches 3 + fi + fi +} + +(( $+functions[_tla_tree_or_rev] )) || +_tla_tree_or_rev () { + _alternative 'trees:tree:_files -/' 'revisions:revision:_tla_revisions' +} + +(( $+functions[_tla_libraries] )) || +_tla_libraries () { + local libraries expl + libraries=($(_call_program tla $TLA my-revision-library)) + _description -V libraries expl "revision libraries" + compadd "$expl[@]" -a libraries +} + +(( $+functions[_tla_my_revision_library] )) || +_tla_my_revision_library () { + if [[ -n $words[(r)-d] ]] || [[ -n $words[(r)--delete] ]]; then + _tla_libraries + else + _files -/ + fi +} + +(( $+functions[_tla_log_versions] )) || +_tla_log_versions () { + local logs expl + if is-at-least 1.1 $tla_version; then + logs=($(_call_program tla $TLA log-versions)) + else + logs=($(_call_program tla $TLA logs)) + fi + _description -V versions expl "log versions" + compadd "$expl[@]" -a logs +} + +# command argument definitions +# commands with different versions + +local cmd_register_archive cmd_archives cmd_ls_archives cmd_redo +local cmd_redo_changes cmd_changes cmd_what_changed cmd_categories +local cmd_branches cmd_versions cmd_cacherev cmd_logs cmd_log_versions +local cmd_log_ls cmd_update cmd_join_branch cmd_replay cmd_deltapatch +local cmd_delta_patch cmd_apply_delta cmd_sync_tree cmd_make_sync_tree +local cmd_delta cmd_revdelta cmd_library_categories cmd_library_branches +local cmd_library_versions cmd_library_revisions + +cmd_log_ls=('*:version:_tla_log_versions') +cmd_log_versions=() +# the options should only complete items that are in the tree + +if is-at-least 1.1 $tla_version; then + cmd_register_archive=('::archive:_tla_archives' ':location:_files -/') + cmd_archives=('::regex:') + cmd_redo=('::changeset:_files -/') + cmd_changes=('::revision:_tla_revisions' + # ':separator:(--)' '*::limit:_files' + #don't understand the limit usage + ) + cmd_categories=('::archive:_tla_archives') + cmd_branches=('::category:_tla_categories') + cmd_versions=('::branch:_tla_branches') + cmd_cacherev=('::revision:_tla_revisions') + #should only complete non-cached revisions + + cmd_logs=($cmd_log_ls) + cmd_update=('::revision:_tla_revisions') + cmd_join_branch=(':revision:_tla_revisions') + #should only complete continuation revisions + + cmd_replay=('*::revision:_tla_revisions') + cmd_deltapatch=(':FROM:_tla_tree_or_rev' ':TO:_tla_tree_or_rev') + cmd_sync_tree=(':revision:_tla_revisions') + cmd_delta=(':FROM:_tla_tree_or_rev' ':TO:_tla_tree_or_rev' '::DEST:_files -/') + cmd_library_categories=('::archive:_tla_archives --library') + cmd_library_branches=('::category:_tla_categories --library') + cmd_library_versions=('::branch:_tla_branches --library') + cmd_library_revisions=('::version:_tla_versions --library') +else + cmd_register_archive=(':archive:_tla_archives' ':location:_files -/') + cmd_archives=() + cmd_redo=() + cmd_changes=('::revision:_tla_revisions') + cmd_categories=() + cmd_branches=(':category:_tla_categories') + cmd_versions=(':branch:_tla_branches') + cmd_cacherev=(':revision:_tla_revisions' '::dir:_files -/') + cmd_logs=($cmd_log_versions) + cmd_update=(':dir:_files -/' '::newdir:_files -/' + '::revision:_tla_revisions') + cmd_join_branch=(':dir:_files -/' '::newdir:_files -/' + ':revision:_tla_revisions') + cmd_replay=(':dir:_files -/' '::newdir:_files -/' '::revision:_tla_revisions') + cmd_deltapatch=(':FROM:_tla_tree_or_rev' ':TO:_tla_tree_or_rev' + ':UPON:_tla_tree_or_rev' '::DEST:_files -/') + cmd_sync_tree=(':dir:_files -/' '::newdir:_files -/' + ':revision:_tla_revisions') + cmd_delta=(':FROM:_tla_tree_or_rev' ':TO:_tla_tree_or_rev') + cmd_library_categories=() + cmd_library_branches=(':category:_tla_categories --library') + cmd_library_versions=(':branch:_tla_branches --library') + cmd_library_revisions=(':version:_tla_versions --library') +fi + +cmd_ls_archives=($cmd_archives) +cmd_redo_changes=($cmd_redo) +cmd_what_changed=($cmd_changes) +cmd_delta_patch=($cmd_deltapatch) +cmd_apply_delta=($cmd_deltapatch) +cmd_make_sync_tree=($cmd_sync_tree) +cmd_revdelta=($cmd_delta) + +# commands the same in all versions + +local cmd_help +cmd_help=() + +local cmd_my_id +cmd_my_id=('::id-string:') + +local cmd_my_default_archive +cmd_my_default_archive=('::archive:_tla_archives') + +local cmd_whereis_archive +cmd_whereis_archive=(':archive:_tla_archives') + +local cmd_init_tree +cmd_init_tree=('::version:_tla_versions') + +local cmd_tree_root +cmd_tree_root=('::directory:_files -/') + +local cmd_tree_version +cmd_tree_version=('::directory:_files -/') + +local cmd_set_tree_version +cmd_set_tree_version=(':version:_tla_versions') + +local cmd_build_config cmd_buildcfg +cmd_build_config=(':config:_tla_config') +cmd_buildcfg=($cmd_build_config) + +local cmd_cat_config cmd_catcfg cmd_cfgcat +cmd_cat_config=(':config:_tla_config') +cmd_catcfg=($cmd_cat_config) +cmd_cfgcat=($cmd_cat_config) + +local cmd_undo cmd_undo_changes +cmd_undo=('::revision:_tla_revisions') +cmd_undo_changes=($cmd_undo) + +local cmd_file_diffs +cmd_file_diffs=(':file:_files' '::revision:_tla_revisions') + +local cmd_file_find +cmd_file_find=(':file:_files' '::revision:_tla_revisions') + +local cmd_inventory cmd_srcfind +cmd_inventory=('::separator:(--)' '*:directory:_files -/') +cmd_srcfind=($cmd_inventory) + +local cmd_tree_lint +cmd_tree_lint=('::directory:_files -/') + +local cmd_id cmd_invtag +cmd_id=('*:file:_files') +cmd_invtag=($cmd_id) + +local cmd_id_tagging_method cmd_tagging_method methods +cmd_id_tagging_method=('::tagging method:(($methods))') +methods=( + 'names:use naming conventions only' + 'implicit:use naming conventions but permit for inventory tags' + 'tagline:use naming conventions but permit for inventory tags' + 'explicit:require explicit designation of source' +) +cmd_tagging_method=($cmd_id_tagging_method) + +local cmd_add cmd_add_id cmd_add_tag +cmd_add=('*:files to add:_files') +cmd_add_id=($cmd_add) +cmd_add_tag=($cmd_add) + +local cmd_delete cmd_delete_id cmd_delete_tag +cmd_delete=('*:files to delete:_files') +cmd_delete_id=($cmd_delete) +cmd_delete_tag=($cmd_delete) + +local cmd_move cmd_move_id cmd_move_tag +cmd_move_id=(':old name:_files' ':new name:_files') +cmd_move_id=($cmd_move) +cmd_move_tag=($cmd_move) +#would be nice not to offer dirs for newname if oldname is a file, and +#vice versa + +local cmd_mv +cmd_mv=('*:file:_files') +# not really right, but close enough + +local cmd_default_id cmd_explicit_default cmd_default_tag +cmd_default_id=('::TAG-PREFIX:') +cmd_explicit_default=($cmd_default_id) +cmd_default_tag=($cmd_default_id) + +local cmd_tagging_defaults cmd_id_tagging_defaults +cmd_tagging_defaults=() +cmd_id_tagging_defaults=($cmd_tagging_defaults) + +local cmd_changeset cmd_mkpatch +cmd_changeset=( + ':ORIG:_files -/' + ':MOD:_files -/' + ':DEST:_files -/' + '*:files:_files' +) +cmd_mkpatch=("$cmd_changeset[@]") + +local cmd_dopatch cmd_do_changeset cmd_apply_changeset +cmd_dopatch=(':changeset:_files -/' ':target:_files -/') +cmd_do_changeset=($cmd_dopatch) +cmd_apply_changeset=($cmd_dopatch) + +local cmd_show_changeset +cmd_show_changeset=('::changeset:_files -/') + +local cmd_make_archive +cmd_make_archive=('::name:' ':location:_files -/') + +local cmd_archive_setup +cmd_archive_setup=('*:versions:_tla_branches --trailing-dashes') + +local cmd_make_category +cmd_make_category=(':category:_tla_archives -S /') + +local cmd_make_branch +cmd_make_branch=(':branch:_tla_categories --trailing-dashes') + +local cmd_make_version +cmd_make_version=(':version:_tla_branches --trailing-dashes') + +local cmd_import cmd_imprev +cmd_import=('::version:_tla_versions') +cmd_imprev=($cmd_import) + +local cmd_commit cmd_cmtrev +cmd_commit=('::version:_tla_versions' ':separator:(--)' '*:files:_files') +cmd_cmtrev=($cmd_commit) + +local cmd_get cmd_getrev +cmd_get=(':revision:_tla_revisions' '::directory:_files -/') +cmd_getrev=($cmd_get) + +local cmd_get_patch cmd_get_changeset +cmd_get_patch=(':revision:_tla_revisions' '::dir:_files -/') +cmd_get_changeset=($cmd_get_patch) + +local cmd_lock_revision +cmd_lock_revision=(':revision:_tla_revisions') + +local cmd_push_mirror cmd_archive_mirror +cmd_push_mirror=( + '::FROM or MINE:_tla_archives' + '::TO:_tla_archives' + '::LIMIT:_tla_limit' +) +cmd_archive_mirror=($cmd_push_mirror) + +local cmd_revisions +cmd_revisions=('::version:_tla_versions') + +local cmd_ancestry +cmd_ancestry=('::revision:_tla_revisions') + +local cmd_ancestry_graph +cmd_ancestry_graph=('::revision:_tla_revisions') + +local cmd_cat_archive_log +cmd_cat_archive_log=(':revision:_tla_revisions') + +local cmd_cachedrevs +cmd_cachedrevs=(':version:_tla_versions') + +local cmd_uncacherev +cmd_uncacherev=(':revision:_tla_revisions' '::dir:_files -/') + +local cmd_archive_meta_info +cmd_archive_meta_info=(':item-name:((name\:foo mirror\:bar))') + +local cmd_archive_snapshot +cmd_archive_snapshot=(':dir:_files -/' '::limit:_tla_revisions') + +local cmd_archive_version +cmd_archive_version=() + +local cmd_archive_fixup +cmd_archive_fixup=() + +local cmd_make_log +cmd_make_log=('::version:_tla_versions') + +local cmd_add_log cmd_add_log_version +cmd_add_log=(':version:_tla_versions') +cmd_add_log_version=($cmd_add_log) + +local cmd_remove_log cmd_remove_log_version +cmd_remove_log=(':version:_tla_log_versions') +cmd_remove_log_version=($cmd_remove_log) + +local cmd_abrowse +cmd_abrowse=('::LIMIT:_tla_revisions') + +local cmd_cat_log +cmd_cat_log=(':revision-spec:_tla_local_revisions') + +local cmd_changelog +cmd_changelog=('::version:_tla_versions') + +local cmd_log_for_merge +cmd_log_for_merge=('::version:_tla_versions') + +local cmd_merges +cmd_merges=(':INTO:_tla_revisions' '::FROM:_tla_revisions') + +local cmd_new_merges +cmd_new_merges=('::version:_tla_versions') + +local cmd_tag cmd_tagrev +cmd_tag=(':SOURCE-REVISION:_tla_revisions' ':TAG-VERSION:_tla_versions') +cmd_tagrev=($cmd_tag) + +local cmd_star_merge +cmd_star_merge=(':FROM:_tla_revisions') + +local cmd_missing cmd_whats_missing +cmd_missing=('::revision:_tla_revisions') +cmd_whats_missing=($cmd_missing) + +local cmd_pristines cmd_ls_pristines +cmd_pristines=('::limit:_tla_revisions') +cmd_ls_pristines=($cmd_pristines) + +local cmd_lock_pristine +cmd_lock_pristine=(':revision:_tla_revisions') + +local cmd_add_pristine +cmd_add_pristine=(':revision:_tla_revisions') + +local cmd_find_pristine +cmd_find_pristine=(':revision:_tla_revisions') + +local cmd_my_revision_library +cmd_my_revision_library=(':library:_tla_my_revision_library') + +local cmd_library_find +cmd_library_find=(':revision:_tla_revisions --library') + +local cmd_library_add +cmd_library_add=(':revision:_tla_revisions --exclude-library-revisions') + +local cmd_library_remove +cmd_library_remove=(':revision:_tla_revisions --library') + +local cmd_library_archives +cmd_library_archives=() + +local cmd_library_log +cmd_library_log=(':revision:_tla_revisions --library') + +local cmd_library_file +cmd_library_file=(':file:_files' ':revision:_tla_revisions --library') + +local cmd_grab +cmd_grab=(':location:_files') + +local cmd_parse_package_name +cmd_parse_package_name=(':name:') + +local cmd_valid_package_name +cmd_valid_package_name=(':name:') + +local cmd_library_config +cmd_library_config=(':library:_tla_libraries') + +local cmd_rbrowse +cmd_rbrowse=('::regular expression:') + +local cmd_rm +cmd_rm=('*:file:_files') + +local cmd_escape +cmd_escape=(':string:') + +#mutually exclusive options + +local -A excludes +excludes=( +# This first line means that if --output was given, don't complete +# --no-output or --keep. The converse is not true. +--output '--no-output --keep' +--no-output --output + +--silent ' --quiet --report --verbose --debug' +--quiet '--silent --report --verbose --debug' +--report '--silent --quiet --verbose --debug' +--verbose '--silent --quiet --report --debug' +--debug '--silent --quiet --report --verbose ' + +--sparse --non-sparse +--non-sparse --sparse + +--files ' --directories --both' +--directories '--files --both' +--both '--files --directories ' + +--mirror --mirror-from +--mirror-from --mirror + +--no-cached --cached-tags +--cached-tags --no-cached + +--non-greedy --greedy +--greedy --non-greedy +) + +_tla_main () { + typeset -A opt_args + local arguments + if (( CURRENT > 2 )); then + local cmd=${words[2]} + local var_cmd=cmd_${cmd//-/_} + curcontext="${curcontext%:*:*}:tla-$cmd:" + (( CURRENT-- )) + shift words + + arguments=() + local input + input=(${${(f)"$($TLA $cmd -h)"}# }) + shift 6 input + + local i j=1 + local short long arg desc action + short=() + long=() + arg=() + desc=() + action=() + for (( i=1 ; i <= ${#input} ; i++ )); do + [[ "$input[i]" != *[^\ ]* ]] && continue # stupid blank lines + short[j]="${${${input[i]}[1,2]}#--}" + long[j]="${${input[i]#-?, }%% *}" + + arg[j]="${${${input[i]%% *}##* }##-*}" + [[ $long[j] == --archive ]] && arg[j]=ARCHIVE # tla doesn't mention this + + desc[j]="${input[i]##* }" + if [[ "$input[i+1]" == \ *[^\ ]* ]]; then # description continues + (( i++ )) + desc[j]="$desc[j] ${input[i]##* }" + fi + desc[j]="${${desc[j]//\[/\\[}//\]/\\]}" # escape brackets + + case $arg[j] in + DIR|PATCH-DIR|DEST|OUTPUT|PATH) + action[j]='_files -/' ;; + FILES|FILE|SNAP-FILE) + action[j]='_files' ;; + MASTER|MASTER-SOURCE|ARCHIVE) + action[j]='_tla_archives' ;; + CATEGORY) + action[j]='_tla_categories' ;; + BRANCH) + action[j]='_tla_branches' ;; + VERSION) + action[j]='_tla_versions' ;; + CFG) + action[j]='_tla_configs' ;; + LIB) + action[j]='_tla_libraries' ;; +# PATCH,FILE) # not sure how to complete this +# action[j]='_tla_patch_file' ;; + *) + action[j]='' ;; + esac + + (( j++ )) + + done + + local excluded k + for (( i = 1 ; i < j ; i++ )); do + excluded=($short[i] $long[i]) + foreach opt (${=excludes[$long[i]]}) + k=$long[(i)$opt] + excluded=($excluded $short[k] $long[k]) + #excludes matching short options too :-) + end + + + # generate arguments to _arguments ;-) + # make long and short options mutually exclusive + [ $short[i] ] && arguments=("$arguments[@]" + "${hide_short}(${excluded})${short[i]}[${desc[i]}]${arg[i]:+:$arg[i]:$action[i]}") + [ $long[i] ] && arguments=("$arguments[@]" + "(${excluded})${long[i]}[${desc[i]}]${arg[i]:+:$arg[i]:$action[i]}") + done + + arguments=("$arguments[@]" "${(@P)var_cmd-*:FILE:_files}") + else + local help + local -U cmds + help=(${(f)"$($TLA help)"}) + cmds=(${${${${(M)help:#* :*}/ #: #/:}%% ##}## #}) + arguments=(':commands:(($cmds))') + fi + _arguments -S -A '-*' \ + {"${hide_short}(: -)-V",'(: -)--version'}'[display version]' \ + {"${hide_short}(: -)-h",'(: -)--help'}'[display help]' \ + '(: -)-H[display verbose help]' \ + "$arguments[@]" +} + +_tla_main "$@" 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 "$@" -- cgit 1.4.1