【问题标题】:ZSH completion removes the argument with compadd -UZSH 完成使用 compadd -U 删除参数
【发布时间】:2018-04-02 15:48:52
【问题描述】:

我正在尝试将完成添加到自定义 vs 函数,该函数基本上打开与参数匹配的第一个文件名。

可选(如果您想了解有关此功能的更多信息,可以在此处找到我的中等帖子 => https://medium.com/@victor.boissiere/how-to-quickly-open-files-with-your-editor-1a51b3fe21bf

在我当前的文件夹中,我有以下内容:

  • ./example.sh
  • ./custom/directory.sh
  • ./custom/example.sh

行为

vs direct<TAB> => 完成到custom/directory.sh SUCCESS

vs example<TAB> => vs

为什么它删除了参数并且不允许我在example.shcustom/example.sh之间进行选择?

代码

_vs() {
  local curcontext="$curcontext" state line expl

  _arguments -C \
    '*:: :->open_files'

  case "$state" in
    open_files)
      local file=${words[CURRENT]}
      compadd -U - `find . -type f -ipath "*$file*" | sed "s|^\./||"`
      ;;
  esac
  return 0
}

compdef _vs vs

【问题讨论】:

    标签: zsh completion


    【解决方案1】:

    感谢这篇文章,我刚刚找到了解决方案 => https://superuser.com/questions/1264778/changing-to-a-directory-found-somewhere-in-the-tree-hierarchy/1278919#1278919

    我只需要添加compstate[insert]=menu # no expand

    解决方案

    _vs() {
      local curcontext="$curcontext" state line expl
    
      _arguments -C \
        '*:: :->open_files'
    
      case "$state" in
        open_files)
          local file=${words[CURRENT]}
          compadd -U - `find . -type f -ipath "*$file*" | sed "s|^\./||"`
          compstate[insert]=menu # add this
          ;;
      esac
      return 0
    }
    
    compdef _vs vs
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多