首页 > 解决方案 > zsh 完成:按子字符串而不是前缀匹配

问题描述

我为我的实用程序编写了一个有效的 ZSH 自动完成功能,_arguments用于指定子命令,然后case根据状态输入处理程序。

$state处理程序中,我_values用来提供子命令可以使用的值。

_actions() {
    local -a actions
    actions=(
      "start:Starts the specified service."
    )
    _describe "Subcommand" actions
}

_arguments \
  '1: :_actions' \
  '*: :->subcommand'

case "$state" in
  subcommand)
    domains=( com.example.foo com.example.bar )
    _values "Domain" $domains
    ;;
esac

但是,for_values的补全只是前缀。有什么方法_values可以显示子字符串匹配?

我匹配的值是逆序 FQDN,例如com.example.fooand com.example.bar,我希望能够键入bar、 hit 和已经com.example.bar完成。

目前,我得到例如

$ mycommand start bar<TAB>
 -- no matches found --

对比

$ mycommand start <TAB>
 -- Domain --
com.example.bar  com.example.foo

有什么方法可以做我想要实现的目标吗?_values如果有一种方法可以通过某些功能定义自定义完成,我不依赖于此。

标签: autocompletezshcompletionzsh-completion

解决方案


推荐阅读