Skip to main content

Python interface for bash completion

Project description

A package that provides python interface for bash completion

Usage example

In the simplest case, we can just complete from the end of the line using, 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'}

However, there is also a lower-level API that more closely matches the actual Bash completion interface, for those who need it!

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)

You may also use this as a simple command line utility:

$ python -m bash_completion "ls --s"
ls --show-control-chars
ls --si
ls --size
ls --sort
ls --sort=

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bash_completion-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file bash_completion-0.1.0.tar.gz.

File metadata

File hashes

Hashes for bash_completion-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb89dcfcccf9f9283538698a7c67b8cdc1256052ea98c3f3246f3ab6879ee664
MD5 400cb73052e9cf365dbbc1b0820045ad
BLAKE2b-256 5bd0d133ff8201479ac39aeb25999ce0875c59dc5f4cb732c98eab31fd826a31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page