在非选项(noDashes)输入后修复zsh _arguments选项(--whatever)完成

时间:2017-01-31 14:50:24

标签: zsh completion

我希望在my gradle completion script中的其他输入之后允​​许--flags完成,但_arguments似乎需要

  

描述选项标志的规范必须在描述分析线的非选项(“位置”或“正常”)参数的规范之前(来自zsh completion docs

换句话说:command foo --o[TAB]什么都不做,但command --o[TAB]工作正常。有没有办法配置_arguments或我是否需要使用其他control functions

注意:在我的情况下,单独的完成功能似乎不是一个选项,因为输入不在固定列表中(gradle任务是任意的,可以指定多个,gradle myfoo mybar --o[TAB]必须工作)。

2 个答案:

答案 0 :(得分:1)

因此,您希望能够输入类似vim foo -[TAB]的内容,并自动展开列表以显示标志和开关,目前您必须键入vim -[TAB]以获取标志和开关,然后键入foo,是吗?

希望我能正确理解你的问题。

我当前的zsh完成选项可能能够帮助解决这个问题,因为我可以做我所描述的,这似乎是你要求的?我已经设置了这些,所以我不记得每个人做了什么。我相信你想要的是setopt COMPLETE_IN_WORDunset LIST_AMBIGUOUS以及zstyle ':completion::approximate*:*' prefix-needed false选项。如果我错了,请纠正我。

我已将我在zsh中使用的内容包含在我的完成部分中。我已将其作为独立测试,它可以在我的zsh上运行。

#{{{ Completion Stuff
zmodload -i zsh/complist
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
bindkey -M viins '\C-i' complete-word
# Faster! (?)
zstyle ':completion::complete:*' use-cache 1
# case insensitive completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' \
  '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 :(得分:1)

我能够用this commit来解决这个问题,至少在指定1个任务后允许选项。

诀窍是使用_arguments:->statename内设置状态,将上下文重置为下一个单词,并提供与非命令单词匹配的通配符匹配器并再次使用_arguments

几乎可以肯定的是,允许在任意数量的单词之后指定选项并避免重复,但这是一个可行的开始。