Python argparse 和 bash 完成 [英] Python argparse and bash completion

查看:23
本文介绍了Python argparse 和 bash 完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也想在参数中自动完成我的 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:

  1. 它使用完成"将完成功能绑定到命令
  2. 每个完成函数基本上都是参数解析器的副本

特别是第二点不是很好,因为我想让它自动生成.

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 为 argparse 提供 bash 补全.

argcomplete provides bash completion for argparse.

这篇关于Python argparse 和 bash 完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆