Fix zsh _arguments parameters (- whatever) after entering without parameters (noDashes)

I would like to allow completion for --flags after another input in my gradle completion script , but _arguments seems to require that

specifications describing option flags must precede specifications describing optional ("positional" or "normal") arguments of the analyzed string (from the completion of zsh documents )

In other words: command foo --o[TAB] does nothing, but command --o[TAB] works fine. Is there a way to configure _arguments or do I need to use other functions?

NOTE. Separate completion functions do not seem to be an option in my case, since the inputs are not in a fixed list (gradle tasks are arbitrary, but several can be specified, gradle myfoo mybar --o[TAB] should work).

+7
zsh
source share
2 answers

I was able to solve this with this commit , at least to resolve the parameters after setting task 1.

The trick is to set the state in _arguments using :->statename , reset the context to the next word and provide a wildcard that matches non-command words, and use _arguments again.

There is almost certainly a way to resolve the parameters given after an arbitrary number of words and to avoid some duplication, but this is a doable start.

+1
source share

So you want to write something like vim foo -[TAB] and open the list automatically to show flags and switches, where you should currently type vim -[TAB] to get your flags and switches, and then type foo , Yes?

I hope I understand your question correctly.

My current zsh completion options could help with this, as I can do what I described, what seems to be what you're asking for? I have long understood that I asked this, so I don’t remember exactly what everyone is doing. However, I believe that you need setopt COMPLETE_IN_WORD , unset LIST_AMBIGUOUS , as well as the parameters zstyle ':completion::approximate*:*' prefix-needed false . If I am wrong, please correct me.

I have included what I use in my zsh as the completion section. I tested this as standalone and it works on my zsh as is.

 #{{{ Completion Stuff zmodload -i zsh/complist zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} bindkey -M viins '\Ci' complete-word # Faster! (?) zstyle ':completion::complete:*' use-cache 1 # case insensitive completion zstyle ':completion:*' matcher-list 'm:{az}={AZ}' \ 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' zstyle ':completion:*' verbose yes zstyle ':completion:*:descriptions' format '%B%d%b' zstyle ':completion:*:messages' format '%d' zstyle ':completion:*:warnings' format 'No matches for: %d' zstyle ':completion:*' group-name '' # generate descriptions with magic. zstyle ':completion:*' auto-description 'specify: %d' # Don't prompt for a huge list, page it! zstyle ':completion:*:default' list-prompt '%S%M matches%s' # Don't prompt for a huge list, menu it! zstyle ':completion:*:default' menu 'select=0' # Have the newer files last so I see them first zstyle ':completion:*' file-sort modification reverse # color code completion zstyle ':completion:*' list-colors "=(#b) #([0-9]#)*=36=31" unsetopt LIST_AMBIGUOUS setopt COMPLETE_IN_WORD # Separate man page sections. zstyle ':completion:*:manuals' separate-sections true # zstyle ':completion:*' list-separator 'fREW' # complete with a menu for xwindow ids zstyle ':completion:*:windows' menu on=0 zstyle ':completion:*:expand:*' tag-order all-expansions # more errors allowed for large words and fewer for small words zstyle ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) )' # Errors format zstyle ':completion:*:corrections' format '%B%d (errors %e)%b' # Don't complete stuff already on the line zstyle ':completion::*:(rm|vi):*' ignore-line true # Don't complete directory we are already in (../here) zstyle ':completion:*' ignore-parents parent pwd zstyle ':completion::approximate*:*' prefix-needed false 
+1
source share

All Articles