bashcomplete.rst
This file
Path
docs/bashcomplete.rst
69 lines · 2.4 KiB
Last changed by
Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
History of this fileTake it
Added basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 1–5why, one step back1Bash Complete2=============34.. versionadded:: 2.05Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 6why, one step back6As of click 2.0, there is built-in support for Bash completion forMerge pull request #104 from julen/doc-fixesArmin Ronacherbefore adoption209faf4
line 7why, one step back7any click script. There are certain restrictions on when this completionMerge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 8why, one step back8is available, but for the most part it should just work.Added basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 9–14why, one step back910Limitations11-----------1213Bash completion is only available if a script has been installed properly14and not executed through the ``python`` command. For information aboutMerge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 15why, one step back15how to do that see :ref:`setuptools-integration`. Also, click currentlyAdded basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 16–17why, one step back16only supports completion for bash.17Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 18why, one step back18Currently, bash completion is an internal feature that is not customizable.Added basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 19–23why, one step back19This might be relaxed in future versions.2021What it Completes22-----------------23Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 24why, one step back24Generally, the bash completion support will complete subcommands andAdded basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 25–28why, one step back25parameters. Subcommands are always listed whereas parameters only if at26least a dash has been provided. Example::2728 $ repo <TAB><TAB>Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 29why, one step back29 clone commit copy delete setuserAdded basic bash complete support.Armin Ronacherbefore adoption4fa40cf
line 30why, one step back30 $ repo clone -<TAB><TAB>Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 31why, one step back31 --deep --help --rev --shallow -rAdded basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 32–35why, one step back3233Activation34----------35Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 36why, one step back36In order to activate Bash completion you need to inform Bash thatAdded basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 37–38why, one step back37completion is available for your script and how. Any click application38automatically provides support for that. The general way this works isMerge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 39why, one step back39through a magic environment variable called ``_<PROG_NAME>_COMPLETE``,Added basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 40–42why, one step back40where ``<PROG_NAME>`` is your application executable name in uppercase41with dashes replaced by underscores.42Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 43why, one step back43If your tool is called ``foo-bar``, then the magic variable is calledAdded basic bash complete support.Armin Ronacherbefore adoption4fa40cf
line 44why, one step back44``_FOO_BAR_COMPLETE``. By exporting it with the ``source`` value it willMerge pull request #104 from julen/doc-fixesArmin Ronacherbefore adoption209faf4
line 45why, one step back45spit out the activation script which can be trivally activated.Added basic bash complete support.Armin Ronacherbefore adoption4fa40cf
line 46why, one step back46Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 47why, one step back47For instance, to enable Bash completion for your ``foo-bar`` script, thisAdded basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 48–51why, one step back48is what you would need to put into your ``.bashrc``::4950 eval "$(_FOO_BAR_COMPLETE=source foo-bar)"51Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 52why, one step back52From this point onwards your script will have Bash completion enabled.Added basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 53–59why, one step back5354Activation 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 alsoMerge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 60why, one step back60ship a file with the contents of that which is what Git and other systemsAdded basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 61–69why, one step back61are 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