diff options
| author | dana <dana@dana.is> | 2026-05-16 19:29:53 -0500 |
|---|---|---|
| committer | dana <dana@dana.is> | 2026-05-16 19:30:07 -0500 |
| commit | 99d875d65689e771e50e3e113e4701522913126b (patch) | |
| tree | b6218c0f4281ed7ffc3063808a78cfe9fd193883 /Completion/Unix/Command | |
| parent | github #161 (tweaked): zkbd: allow zkbd to generate config in a custom directory (diff) | |
| download | zsh-99d875d65689e771e50e3e113e4701522913126b.tar zsh-99d875d65689e771e50e3e113e4701522913126b.tar.gz zsh-99d875d65689e771e50e3e113e4701522913126b.tar.bz2 zsh-99d875d65689e771e50e3e113e4701522913126b.tar.lz zsh-99d875d65689e771e50e3e113e4701522913126b.tar.xz zsh-99d875d65689e771e50e3e113e4701522913126b.tar.zst zsh-99d875d65689e771e50e3e113e4701522913126b.zip | |
github #169: completion: update _darcs from up-stream
this function is now provided by the up-stream project, so it will be removed
from the zsh distribution. this commit exists to back-port into 5.9.1 -- i felt
the history might be confusing if the update appeared only in that branch
Diffstat (limited to 'Completion/Unix/Command')
| -rw-r--r-- | Completion/Unix/Command/_darcs | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/Completion/Unix/Command/_darcs b/Completion/Unix/Command/_darcs index 73d6b6b18..cc81ba6bb 100644 --- a/Completion/Unix/Command/_darcs +++ b/Completion/Unix/Command/_darcs @@ -13,26 +13,51 @@ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. -local expl +local -a darcs_options darcs_non_options darcs_arguments darcs_list_options if (($CURRENT == 2)); then - # We're completing the first word after "darcs" -- the command. - _wanted command expl 'darcs command' \ - compadd -- $( darcs --commands ) + compadd -- $(darcs --commands) else - case "${words[$CURRENT]}" in - # If it looks like an URL... - ht*|ft*) - _arguments '*:URL:_urls' - ;; - # If it looks like an explicit path... + # advanced zsh (array) parameter expansion fu: + # - ${(f)...} means split into array elements at line endings + # instead of white space + # - ${arr:#pat} drops elements matching pat from arr, whereas + # ${(M)arr:#pat} drops non-matching elements + # - ${arr/pat/repl} replaces pat with repl for all elements of arr + # - ${arr[(i)val]} is reverse indexing: returns index of first + # occurrence of val in arr + + # save current word + local current_word=$words[$CURRENT] + # delete it from words + words[$CURRENT]=() + # find the index of the first option argument + local first_opt=${words[(i)-*]} + # insert --list-options right before the first option argument + darcs_list_options=($words[1,$(($first_opt - 1))] --list-options $words[$first_opt,-1]) + # debugging help + #print -l $darcs_list_options > ./debug_darcs_completion + # execute command line with --list-options inserted and + # split the result (stdout) at line endings + darcs_arguments=(${(f)"$($darcs_list_options 2>/dev/null)"}) + case $current_word; in /*|./*|\~*|../*) - _arguments '*:file:_files' - ;; - # Otherwise, let's ask darcs for all possible options + _files + ;; + -*) + darcs_options=(${${(M)darcs_arguments:#-*}/;/:}) + _describe '' darcs_options + ;; *) - _wanted args expl 'arg for darcs command' \ - compadd -- $( darcs ${words[2]} --list-option ) + case "${words[2]}"; in + get|clone) + _urls + ;; + *) + darcs_non_options=(${darcs_arguments:#-*}) + _multi_parts -i -S ' ' / darcs_non_options + ;; + esac ;; esac fi |
