Skip to main content

Automagic shell tab completion for Python CLI applications

Project description

Logo

shtab

Tests Coverage conda-forge PyPI

  • 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

See operating system-specific instructions in the docs.

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}

    • subparser mode: end-users execute your_cli_app completion {bash,zsh}

Examples

See the docs for usage examples.

FAQs

Not working? Check out frequently asked questions.

Alternatives

  • argcomplete

    • executes the underlying script every time <TAB> is pressed (slow and has side-effects)

    • only provides bash completion

  • pyzshcomplete

    • executes the underlying script every time <TAB> is pressed (slow and has side-effects)

    • only provides zsh completion

  • click

    • 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.

Hits

Download files

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

Source Distribution

shtab-1.5.8.tar.gz (45.7 kB view details)

Uploaded Source

Built Distribution

shtab-1.5.8-py2.py3-none-any.whl (13.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file shtab-1.5.8.tar.gz.

File metadata

  • Download URL: shtab-1.5.8.tar.gz
  • Upload date:
  • Size: 45.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for shtab-1.5.8.tar.gz
Algorithm Hash digest
SHA256 1f944e2e33c1554be69e6b26ef638ba3b516ac9449fdd2a40d197f9061c8bed8
MD5 5857270c2dcd0c43e80afad19e40a101
BLAKE2b-256 3c4c7d8363edcd34b5fb6d5fd24be8224cdae2de39bc558a84394655822b0ef3

See more details on using hashes here.

Provenance

File details

Details for the file shtab-1.5.8-py2.py3-none-any.whl.

File metadata

  • Download URL: shtab-1.5.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for shtab-1.5.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1d326ea131edbba96e0489470a2c969da1976a586a2d9376bb4923a6fe8eaae0
MD5 e341757e0ada189f07e962b41ce3f949
BLAKE2b-256 f1cde9b253ad8de9fa9bc7f4c1b2aa60332632a9432c77b227a62a97aefba12a

See more details on using hashes here.

Provenance

Supported by

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