shtab

Automagic shell tab completion for Python CLI applications

47 个版本 Python >=3.9
安装
pip install shtab
poetry add shtab
pipenv install shtab
conda install shtab
描述

|Logo|

shtab

|PyPI-Downloads| |Tests| |Coverage| |PyPI| |Conda|

  • What: Automatically generate shell tab completion scripts for Python CLI apps
  • Why: Speed & correctness. Alternatives like argcomplete <https://pypi.org/project/argcomplete>_ and pyzshcomplete <https://pypi.org/project/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

    • argparse <https://docs.python.org/library/argparse>_
    • docopt <https://pypi.org/project/docopt>_ (via argopt <https://pypi.org/project/argopt>_)
  • 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})


.. contents:: Table of Contents :backlinks: top

Installation

Choose one of:

  • pip install shtab, or
  • conda install -c conda-forge shtab

See operating system-specific instructions in the docs <https://docs.iterative.ai/shtab/#installation>_.

Usage

There are two ways of using shtab:

  • CLI Usage <https://docs.iterative.ai/shtab/use/#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 <https://docs.iterative.ai/shtab/use/#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

See the docs for usage examples <https://docs.iterative.ai/shtab/use/#main.py>_.

FAQs

Not working? Check out frequently asked questions <https://docs.iterative.ai/shtab/#faqs>_.

Alternatives

  • argcomplete <https://pypi.org/project/argcomplete>_

    • executes the underlying script every time <TAB> is pressed (slow and has side-effects)
  • pyzshcomplete <https://pypi.org/project/pyzshcomplete>_

    • executes the underlying script every time <TAB> is pressed (slow and has side-effects)
    • only provides zsh completion
  • click <https://pypi.org/project/click>_

    • different framework completely replacing the builtin argparse
    • solves multiple problems (rather than POSIX-style "do one thing well")

Contributions

Please do open issues <https://github.com/iterative/shtab/issues>_ & pull requests <https://github.com/iterative/shtab/pulls>_! Some ideas:

  • support fish (#174 <https://github.com/iterative/shtab/pull/174>_)
  • support powershell

See CONTRIBUTING.md <https://github.com/iterative/shtab/tree/main/CONTRIBUTING.md>_ for more guidance.

|Hits|

.. |Logo| image:: https://github.com/iterative/shtab/raw/main/meta/logo.png .. |Tests| image:: https://img.shields.io/github/actions/workflow/status/iterative/shtab/test.yml?logo=github&label=tests :target: https://github.com/iterative/shtab/actions :alt: Tests .. |Coverage| image:: https://codecov.io/gh/iterative/shtab/branch/main/graph/badge.svg :target: https://codecov.io/gh/iterative/shtab :alt: Coverage .. |Conda| image:: https://img.shields.io/conda/v/conda-forge/shtab.svg?label=conda&logo=conda-forge :target: https://anaconda.org/conda-forge/shtab :alt: conda-forge .. |PyPI| image:: https://img.shields.io/pypi/v/shtab.svg?label=pip&logo=PyPI&logoColor=white :target: https://pypi.org/project/shtab :alt: PyPI .. |PyPI-Downloads| image:: https://img.shields.io/pypi/dm/shtab.svg?label=pypi%20downloads&logo=PyPI&logoColor=white :target: https://pepy.tech/project/shtab :alt: Downloads .. |Hits| image:: https://cgi.cdcl.ml/hits?q=shtab&style=social&r=https://github.com/iterative/shtab&a=hidden :target: https://cgi.cdcl.ml/hits?q=shtab&a=plot&r=https://github.com/iterative/shtab&style=social :alt: Hits

分类
Development Status :: 5 - Production/Stable Environment :: Console Environment :: MacOS X Environment :: Other Environment Intended Audience :: Developers Intended Audience :: Education Intended Audience :: End Users/Desktop Intended Audience :: Other Audience Intended Audience :: System Administrators Operating System :: MacOS Operating System :: MacOS :: MacOS X Operating System :: POSIX Operating System :: POSIX :: BSD Operating System :: POSIX :: BSD :: FreeBSD Operating System :: POSIX :: Linux Operating System :: POSIX :: SunOS/Solaris Operating System :: Unix Programming Language :: Other Scripting Engines Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 Programming Language :: Python :: 3.13 Programming Language :: Python :: 3.9 Programming Language :: Python :: Implementation Programming Language :: Python :: Implementation :: IronPython Programming Language :: Python :: Implementation :: PyPy Programming Language :: Unix Shell Topic :: Desktop Environment Topic :: Education :: Computer Aided Instruction (CAI) Topic :: Education :: Testing Topic :: Office/Business Topic :: Other/Nonlisted Topic Topic :: Software Development Topic :: Software Development :: Build Tools Topic :: Software Development :: Libraries Topic :: Software Development :: Libraries :: Python Modules Topic :: Software Development :: Pre-processors Topic :: Software Development :: User Interfaces Topic :: System Topic :: System :: Installation/Setup Topic :: System :: Shells Topic :: System :: System Shells Topic :: Terminals Topic :: Utilities
版本列表
1.8.0 2025-11-18
1.7.2 2025-04-12
1.7.1 2024-03-07
1.7.0 2024-02-20
1.6.5 2023-12-02
1.6.4 2023-07-28
1.6.3 2023-07-24
1.6.2 2023-06-14
1.6.1 2023-04-03
1.6.0 2023-04-02
1.5.8 2022-11-18
1.5.7 2022-11-02
1.5.6 2022-10-29
1.5.5 2022-06-17
1.5.4 2022-04-19
1.5.3 2022-01-02
1.5.2 2021-12-02
1.5.1 2021-11-23
1.5.0 2021-11-16
1.4.2 2021-10-11
1.4.1 2021-09-01
1.4.0 2021-08-24
1.3.10 2021-08-04
1.3.9 2021-07-20
1.3.8 2021-07-08
1.3.7 2021-07-03
1.3.6 2021-05-03
1.3.5 2021-02-22
1.3.4 2020-12-28
1.3.3 2020-11-29
1.3.2 2020-09-30
1.3.1 2020-08-16
1.3.0 2020-08-04
1.2.0 2020-07-29
1.1.1 2020-07-29
1.1.0 2020-07-01
1.0.5 2020-06-29
1.0.4 2020-06-27
1.0.3 2020-06-26
1.0.2 2020-06-21
1.0.1 2020-06-19
1.0.0 2020-06-19
0.0.4 2020-06-19
0.0.3 2020-06-18
0.0.2 2020-06-17
0.0.1 2020-06-17
0.0.0 2020-06-17