I believe most folks have written a bash or Python app/tool that runs from the terminal command line to do
some useful stuff. These programs usually accept some parameters and options. And it's really cool when you can press the
TAB key and get the list of options the command expects:
$ git ch<TAB> ... checkout -- checkout branch or paths to working tree checkout-index -- copy files from index to working directory
🦾 It seems to be a minor thing but it boosts your productivity significantly! Enough for a search query
productivity terminal autocompleteto generate almost a million results.
The simplest answer is Shtab - a Python library that can analyze your code and generate necessary files for
zsh shell to give your tools the same powerful functionality💥 .
😱 Every time a new feature is added, maintainers and contributors have to update tab completion scripts for multiple supported shells. At best, it's a pain, and at worst, error-prone.
For Python CLI application using
argopt simply hand your parser object to
shtab (either via the CLI or the Python API), and a tab completion script will be generated for your preferred shell. It's as easy as:
$ shtab --shell=bash myprogram.main.parser
or in Python:
import shtab print(shtab.complete(parser, shell="bash"))
That's how Git for Data's in terminal looks like when completion is installed:
% dvc <TAB> Completing dvc commands add -- Track data files or directories with DVC. cache -- Manage cache settings. checkout -- Checkout data files from cache. commit -- Save changed data to cache and update DVC-files. completion -- Prints out shell tab completion scripts. At Top: Hit TAB for more, or the character to insert
I hope you'll find it useful and this lib will save you some time! As usual, give the project a ⭐️ to thank the author and welcome to the issue tracker or comments 👇 if you have any questions.