bashcomplete.rst
This file
Path
docs/bashcomplete.rst
69 lines · 2.4 KiB
Last changed by
Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
History of this fileTake it
The walk stopped after 200 commits: lines older than a489e0e point at it.
Merge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoptiona489e0e
lines 1–5why, one step back1Bash Complete2=============34.. versionadded:: 2.05Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
lines 6–7why, one step back6As of Click 2.0, there is built-in support for Bash completion for7any Click script. There are certain restrictions on when this completionMerge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoptiona489e0e
lines 8–14why, one step back8is available, but for the most part it should just work.910Limitations11-----------1213Bash completion is only available if a script has been installed properly,14and not executed through the ``python`` command. For information aboutMerge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
line 15why, one step back15how to do that, see :ref:`setuptools-integration`. Also, Click currentlyMerge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoptiona489e0e
lines 16–36why, one step back16only supports completion for Bash.1718Currently, Bash completion is an internal feature that is not customizable.19This might be relaxed in future versions.2021What it Completes22-----------------2324Generally, the Bash completion support will complete subcommands and25parameters. Subcommands are always listed whereas parameters only if at26least a dash has been provided. Example::2728 $ repo <TAB><TAB>29 clone commit copy delete setuser30 $ repo clone -<TAB><TAB>31 --deep --help --rev --shallow -r3233Activation34----------3536In order to activate Bash completion, you need to inform Bash thatMerge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
line 37why, one step back37completion is available for your script, and how. Any Click applicationMerge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoptiona489e0e
lines 38–69why, one step back38automatically provides support for that. The general way this works is39through a magic environment variable called ``_<PROG_NAME>_COMPLETE``,40where ``<PROG_NAME>`` is your application executable name in uppercase41with dashes replaced by underscores.4243If your tool is called ``foo-bar``, then the magic variable is called44``_FOO_BAR_COMPLETE``. By exporting it with the ``source`` value it will45spit out the activation script which can be trivally activated.4647For instance, to enable Bash completion for your ``foo-bar`` script, this48is what you would need to put into your ``.bashrc``::4950 eval "$(_FOO_BAR_COMPLETE=source foo-bar)"5152From this point onwards, your script will have Bash completion enabled.5354Activation Script55-----------------5657The above activation example will always invoke your application on58startup. This might be slowing down the shell activation time59significantly if you have many applications. Alternatively, you could also60ship a file with the contents of that, which is what Git and other systems61are doing.6263This can be easily accomplished::6465 _FOO_BAR_COMPLETE=source foo-bar > foo-bar-complete.sh6667And then you would put this into your bashrc instead::6869 . /path/to/foo-bar-complete.sh