✨ Shtab : Pythonアプリケーションの自動補完を提供する


私はほとんどの人々は、bashやPythonのアプリケーションを書いている/ツールは、ターミナルコマンドラインから実行するにはsome useful stuff . これらのプログラムは通常いくつかのパラメータとオプションを受け入れます.そして、あなたが押すことができるとき、それは本当に涼しいですTAB キーとコマンドが期待するオプションのリストを取得します.
$ 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 autocomplete to generate almost a million results.



だから、どのようにあなたのPythonアプリケーションの同じ魔法を行うことができますか?
最も簡単な答えはShtab - コードを解析し、必要なファイルを生成できるPythonライブラリbash or zsh あなたのツールに同じ強力な機能を与えるシェル💥 .
このツールはCasper のメンテナンスを自動化するDVC プロジェクト

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



さて、十分な話をしましょう🎥.
Python CLIアプリケーションではargparse , docopt , or argopt 単にパーサオブジェクトをshtab ( CLIかPython APIを経由して)いずれかのタブでスクリプトを生成します.以下のように簡単です.
$ shtab --shell=bash myprogram.main.parser
またはPythonで
import shtab
print(shtab.complete(parser, shell="bash"))
それでGit for Data's 端末では完成がインストールされているかのように見えます.
% 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
私はあなたが役に立つことを願って、このlibはいくつかの時間を節約します!いつものように、プロジェクトAを与える⭐️ 感謝するauthor と問題トラッカーやコメントへようこそ👇 質問があれば.