我应该如何在 zsh 中使用 argcomplete?

How should I use argcomplete in zsh?

我正在使用 argcomplete 在 Bash 中完成 Tab

argcompletebash 提供全局完成,但不为 zsh

我想创建一个文件 ~/.zsh_completion,以包含待完成的文件。当该文件来自 ~/.zshrc.

时,它应该为这些文件生成自动完成

我该怎么做?

好吧,有办法做到这一点,但这不是我真正想要的方式。

无论如何,这里是:

  1. 安装argcomplete:

    $ pip install argcomplete
    
  2. 激活argcompolete:

    $ activate-global-python-argcomplete --user
    
  3. 将此添加到 ~/.zshrc:

    autoload bashcompinit
    bashcompinit
    source ~/.bash_completion.d/python-argcomplete.sh
    
    eval "$(register-python-argcomplete /path/to/the/to/be/completed/file1)"
    eval "$(register-python-argcomplete /path/to/the/to/be/completed/file2)"
    eval "$(register-python-argcomplete /path/to/the/to/be/completed/file3)"
    

    从另一个文件中读出待完成的文件可能有解决方案,但我不知道该怎么做。

与 Exeleration-G 相同,但在你的 ~/.zshrc 中你只需要输入

eval "$(cd path/to/script; register-python-argcomplete script.name)"

我刚刚发布了一个名为 pyzshcomplete 的新项目,可以在 here 中找到。 它旨在提供与 argcomplete 相同的功能,但 zsh.