Automagic shell tab completion for Python CLI applications
Project description
shtab
What: Automatically generate shell tab completion scripts for Python CLI apps
Why: Speed & correctness. Alternatives like argcomplete and pyzshcomplete are slow and have side-effects
How: shtab processes an argparse.ArgumentParser object to generate a tab completion script for your shell
Features
Outputs tab completion scripts for
bash
zsh
tcsh
Supports
Supports arguments, options and subparsers
Supports choices (e.g. --say={hello,goodbye})
Supports file and directory path completion
Supports custom path completion (e.g. --file={*.txt})
Installation
Choose one of:
pip install shtab, or
conda install -c conda-forge shtab
Usage
There are two ways of using shtab:
CLI Usage: shtab’s own CLI interface for external applications
may not require any code modifications whatsoever
end-users execute shtab your_cli_app.your_parser_object
Library Usage: as a library integrated into your CLI application
adds a couple of lines to your application
argument mode: end-users execute your_cli_app --print-completion {bash,zsh,tcsh}
subparser mode: end-users execute your_cli_app completion {bash,zsh,tcsh}
Examples
FAQs
Not working? Check out frequently asked questions.
Alternatives
-
executes the underlying script every time <TAB> is pressed (slow and has side-effects)
only provides bash completion
-
executes the underlying script every time <TAB> is pressed (slow and has side-effects)
only provides zsh completion
-
different framework completely replacing the builtin argparse
solves multiple problems (rather than POSIX-style “do one thing well”)
Contributions
Please do open issues & pull requests! Some ideas:
support fish
support powershell
See CONTRIBUTING.md for more guidance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file shtab-1.7.1.tar.gz
.
File metadata
- Download URL: shtab-1.7.1.tar.gz
- Upload date:
- Size: 45.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e4bcb02eeb82ec45920a5d0add92eac9c9b63b2804c9196c1f1fdc2d039243c |
|
MD5 | da7bd07a2b2888974d6bf5c4ea70cdcf |
|
BLAKE2b-256 | a9e413bf30c7c30ab86a7bc4104b1c943ff2f56c1a07c6d82a71ad034bcef1dc |
File details
Details for the file shtab-1.7.1-py3-none-any.whl
.
File metadata
- Download URL: shtab-1.7.1-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32d3d2ff9022d4c77a62492b6ec875527883891e33c6b479ba4d41a51e259983 |
|
MD5 | 3e86a240d7cc664592d78c7c2415b31e |
|
BLAKE2b-256 | e2d1a1d3189e7873408b9dc396aef0d7926c198b0df2aa3ddb5b539d3e89a70f |