shtab(1)
π NAME π
okay so bestie, gather round β shtab is Automagic shell tab completion for Python CLI applications β¨ and yes, "automagic" is the actual official word, we don't make the rules, we just slay by them π
π SYNOPSIS π
shtab [OPTIONS] PARSER
πΈ DESCRIPTION πΈ
shtab automatically generates shell tab completion scripts for Python CLI applications, no cap. It takes an argparse.ArgumentParser object β or, plot twist, a function that returns one π β and turns it into a tab completion script for your shell. Literally it does the tedious part so you don't have to, iconic behaviour fr fr.
The generated completion scripts support bash, zsh, and tcsh shells. Three shells, one tool, main character energy only π¦
β¨ OPTIONS β¨
parserβ the importable parser (or a function returning a parser) you want completions for, written in the formatmodule.parser_objectormodule.function_returning_parser. Yes it's positional, yes it goes at the end, it's the whole point of the show π-s,--shell=SHELLβ which shell you're targeting with the completion script. Supported shells:bash,zsh,tcsh. Default:bash.-o,--output=FILEβ where to write the output file path. Use-for stdout, which is the default π«Ά--prefix=PREFIXβ stick this prefix in front of the generated functions so your naming doesn't clash with anything else. Very "let me label my stuff" of you, we love a boundary β¨--preamble=TEXTβ prepend this text to the generated script. Little intro, little vibe-setter π--prog=PROGRAMβ custom program name, which overrides the parser'sprogattribute. Yes you can rename the whole situation π-u,--error-unimportableβ raise errors if the specified parser is not found in$PYTHONPATH. Bestie, by default import errors are silently ignored, which is giving "quiet quitting" β this flag makes it actually speak up π--verboseβ enable debug logging. For when you simply must know everything π--print-own-completion=SHELLβ printshtab's own completion script for the specified shell. Yes, the tool can tab-complete itself, it's self-care π--versionβ display version information and exit. Short, sweet, periodt β
π¦ USAGE π¦
There are two ways of using shtab, and honestly both are valid, we don't pick favourites:
π» CLI Usage π»
Use shtab's own CLI interface for external applications. This may not require any code modifications at all β zero notes, we love a low-effort win. End-users execute:
shtab your_cli_app.your_parser_object
π Library Usage π
Integrate shtab as a library into your CLI application. This adds a couple of lines to your application (just a couple, promise π«Ά). End-users execute:
your_cli_app --print-completion {bash,zsh,tcsh}
or
your_cli_app completion {bash,zsh,tcsh}
π₯ EXAMPLES π₯
πΈ Bash completion πΈ
Generate and install bash completion for an application:
shtab --shell=bash myapp.main.get_parser | sudo tee
"$BASH_COMPLETION_COMPAT_DIR"/myapp
π Zsh completion π
Generate and install zsh completion β and bestie, note the underscore prefix, it matters, don't skip it:
shtab --shell=zsh myapp.main.get_parser | sudo tee
/usr/local/share/zsh/site-functions/_myapp
π Tcsh completion π
Generate and install tcsh completion:
shtab --shell=tcsh myapp.main.get_parser | sudo tee
/etc/profile.d/myapp.completion.csh
β‘ Eager bash completion β‘
Automatically update completions each time a terminal is opened. It's giving "always fresh, never stale" β¨:
echo 'eval "$(shtab --shell=bash myapp.main.get_parser)"' >>
~/.bash_completion
π§ Eager zsh completion π§
Add to ~/.zshrc:
mkdir -p ~/.zsh/completions
fpath=($fpath ~/.zsh/completions)
shtab --shell=zsh myapp.main.get_parser -o
~/.zsh/completions/_myapp
π Custom program name π
Override the program name in the generated completion:
shtab --prog=myprog myapp.main.get_parser
π SEE ALSO π
argparse(3), bash(1), zsh(1), tcsh(1) β the whole friend group, go say hi π«Ά
π AUTHOR π
shtab was written by the tqdm team. Absolute legends, no notes π
and that's the tea, bestie β this was shtab manual page, version 1.8.0, dated 2026, and ngl you ate that read πβ¨ go forth and tab-complete everything, periodt π
π¦ where this page comes from
- ubuntu stonking: python3-shtab 1.12.1-1 Β· MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms