Python argparse和bash完成 [英] Python argparse and bash completion
问题描述
我想在参数中也自动完成我的python脚本.
I would like to get auto-completion on my python scripts also in the arguments.
我从来没有真正理解过bash_completion是如何工作的(用于参数),但是当我深入研究后,我明白了:
I had never really understood how the bash_completion worked (for arguments), but after I digged in I understood that:
- 它使用"complete"将完成功能绑定到命令
- 每个完成函数基本上都是参数解析器的副本
第二点特别不好,因为我想让它自动生成.
The second point in particular is not great, because I would like to have it automatically generated.
最好的办法是,shell在每个TAB处都向我的程序询问要完成什么,但是我有一种印象,那就是这真的行不通,对吗?
The best thing would be that the shell asks to my program at every TAB about what to complete, but I have the impression that this can't really work, is that correct?
第二种选择可能只是将一个转换器从argparse解析器写入正确完成的shell函数.
The second option is probably just to write a converter from an argparse parser to a shell function which completes correctly.
推荐答案
无耻的自我宣传: https://github.com/kislyuk/argcomplete
argcomplete为argparse提供bash完成.
argcomplete provides bash completion for argparse.
这篇关于Python argparse和bash完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!