How should I use argcomplete in zsh?

一曲冷凌霜 提交于 2020-01-24 04:25:29

问题


I'm using argcomplete to have Tab completion in Bash.

argcomplete offers global completion for bash, but doesn't for zsh.

I would like to create a file ~/.zsh_completion, to contain the to be completed files. This file should generate autocompletion for those files when it's sourced from ~/.zshrc.

How do I do that?


回答1:


Alright there is a way to do it, but it's not the way I really wanted it to be.

Anyway, here goes:

  1. Install argcomplete:

    $ pip install argcomplete
    
  2. Activate argcompolete:

    $ activate-global-python-argcomplete --user
    
  3. Add this to ~/.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)"
    

    There's probably a solution to read out the to be completed files from another file, but I don't know how to do that.




回答2:


Same as Exeleration-G but in your ~/.zshrc you only put

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


来源:https://stackoverflow.com/questions/30637837/how-should-i-use-argcomplete-in-zsh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!