Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Example on how to set up shell autocomplete for Python scripts.

License

NotificationsYou must be signed in to change notification settings

ggirelli/python-click-autocomplete-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an example on how to set up shell autocompletion for your Python scripts reading input viaclick, especially when working on a Python package usingPoetry.

Requirements

To test this example you will need:

  • Python v3.8+
  • Poetry

Usage

Set up the example's environment and enter it with:

git clone https://github.com/ggirelli/python-click-autocomplete-example.gitcd python-click-autocomplete-examplepoetry installpoetry shell

This example package provides you with two scripts:

  • clicko is a placeholder mimicking a normal script with subcommands and commands.
  • clicko-autocomplete can be used to enable autocompletion for theclicko script.

Currently, autocompletion is supported forbash,fish, andzsh. To activate it, simply run:

clicko-autocomplete -s SHELL_TYPE

The defaultSHELL_TYPE isbash.

Now, you should be able to test autocompletion by typingclicko <TAB> <TAB>.

How does it work

Theclicko-autocomplete script is able to generate and install shell autocompletion configuration files, stored by default in theautocomplete subfolder of this package. This is done by exploiting the in-built autocompletion tools served byclick.

When installing the autocompletion configuration files forbash orzsh, theclicko-autocomplete script is able to check if the config files were already installed, and avoid re-installation.

To read more on autocompletion withclick, check outtheir documentation.


[8]ページ先頭

©2009-2025 Movatter.jp