diff options
Diffstat (limited to 'Completion/Unix/Command/_darcs')
| -rw-r--r-- | Completion/Unix/Command/_darcs | 508 |
1 files changed, 501 insertions, 7 deletions
diff --git a/Completion/Unix/Command/_darcs b/Completion/Unix/Command/_darcs index 7aa57643b..fe5c9842f 100644 --- a/Completion/Unix/Command/_darcs +++ b/Completion/Unix/Command/_darcs @@ -1,11 +1,505 @@ #compdef darcs -if (($CURRENT == 2)); then - # We're completing the first word after "darcs" -- the command. - _wanted command expl 'darcs command' \ - compadd -- $( darcs --commands ) +# EXTENDED_GLOB is required fr pattern backreferences. +setopt EXTENDED_GLOB + +local DARCS=$words[1] + +# test whether to hide short options from completion +autoload is-at-least +local hide_short +if zstyle -s ":completion:${curcontext}" hide-shortopts hide_short; then + case $hide_short in + true|yes|on|1) hide_short='!' ;; + *) hide_short='' ;; + esac else - # Find the options/files/URL/etc. for the current command by using darcs. - _wanted args expl 'arg for darcs command' \ - compadd -- $( darcs ${words[2]} --list-option ) + is-at-least 4.1 || hide_short='!' fi + + + +_darcs_main() { +# Based on section 6.8 of _A User's Guide to the Z-Shell_ by Peter Stephenson. +# Also based on the tla completion module by Jason McCarty. How do I credit +# this? +local DARCS=$words[1] +local arguments +local curcontext="$curcontext" + +if (( CURRENT > 2 )); then + local cmd=${words[2]} + local var_cmd=cmd_${cmd//-/_} + curcontext="${curcontext%:*:*}:darcs-${cmd}:" + (( CURRENT-- )) + shift words + + local short long arg desc action + short=() + long=() + arg=() + desc=() + action=() + arguments=() + + # Collect all help lines which have a leading space. + local input + input=(${(f)"$($DARCS $cmd -h)"}) + input=(${input:#[^\ ]*}) + local i + for (( i=1 ; i <= ${#input} ; i++ )); do + # Assumption: the the argument descriptions from `darcs cmd -h` + # have the following format: + # [spaces]<-f>[spaces][--flag]<=<spaces>argument>[spaces][description] + [[ "$input[i]" = (#b)' '#(-?|)' '#([^' ']#|)' '#(--[^=' ']#)(=([^' ']#)|)' '#(*) ]] \ + || _message -e messages "cannot parse command help output." || return 1 + + short[i]="$match[1]" + long[i]="$match[3]" + arg[i]="$match[5]" + desc[i]="$match[6]" + desc[i]="${${desc[i]//\[/\\[}//\]/\\]}" # escape brackets + + case $arg[i] in + DIRECTORY) + action[i]='_files -/' ;; + FILE|FILENAME|IDFILE|KEYS) + action[i]='_files' ;; + USERNAME) + action[i]='_users' ;; + EMAIL|FROM) + action[i]='_email_addresses' ;; + *) + action[i]='' ;; + esac + done + |
