bash完成的python接口
bash_completion的Python项目详细描述
为bash完成提供python接口的包
用法示例
在最简单的情况下,我们可以使用bash_complete_line():
frombash_completionimportbash_complete_lineIn[1]:bash_complete_line('git s',return_line=True)Out[1]:{'git shortlog','git show','git show-branch','git stage','git stash','git status','git submodule','git subtree'}
但是,还有一个较低级别的api,它与实际的bash完成更为接近 界面,为那些需要它的人!
frombash_completionimportbash_completionsdefget_completions(line):split=line.split()iflen(split)>1andnotline.endswith(' '):prefix=split[-1]begidx=len(line.rsplit(prefix)[0])else:prefix=''begidx=len(line)endidx=len(line)returnbash_completions(prefix,line,begidx,endidx)In[1]:get_completions('git s')Out[1]:({'shortlog','show','show-branch','stage','stash','status','submodule','subtree'},1)
您也可以将其用作一个简单的命令行实用程序:
$ python -m bash_completion "ls --s" ls --show-control-chars ls --si ls --size ls --sort ls --sort=