bash completion的Python接口
项目描述
提供bash completion的Python接口的软件包
使用示例
在最简单的情况下,我们可以使用 bash_complete_line() 从行尾进行补全
from bash_completion import bash_complete_line
In [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'}但是,还有更接近实际Bash completion接口的低级别API,供需要的人使用!
from bash_completion import bash_completions
def get_completions(line):
    split = line.split()
    if len(split) > 1 and not line.endswith(' '):
        prefix = split[-1]
        begidx = len(line.rsplit(prefix)[0])
    else:
        prefix = ''
        begidx = len(line)
    endidx = len(line)
    return bash_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=