Skip to content

Enabling Autocomplete

All of this information is taken from the click documentation, and you should read it if you want to know more. In order for completion to be used, the user needs to register a special function with their shell. The script is different for every shell, and Click will output it for bookshelf when called with _BOOKSHELF_COMPLETE set to {shell}_source. The built-in shells are bash, zsh, and fish.

Using Eval

Add this to ~/.bashrc:

eval "$(_BOOKSHELF_COMPLETE=bash_source bookshelf)"

Using an Activation Script

Using eval means that the command is invoked and evaluated every time a shell is started, which can delay shell responsiveness. To speed it up, write the generated script to a file, then source that. You can generate the files ahead of time and distribute them with your program to save your users a step.

Save the script somewhere.

_BOOKSHELF_COMPLETE=bash_source bookshelf > ~/.bookshelf-complete.bash

Source the file in ~/.bashrc.

. ~/.bookshelf-complete.bash