Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than cf8f1b7 point at it.

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 1–5why, one step back
1Bash Complete
2=============34.. versionadded:: 2.05

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

lines 6–7why, one step back
6As of Click 2.0, there is built-in support for Bash completion for
7any Click script. There are certain restrictions on when this completion

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

line 8why, one step back
8is available, but for the most part it should just work.

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 9–12why, one step back
9
10Limitations11-----------12

Documentation fixesKevin Yapbefore adoption67523af

line 13why, one step back
13Bash completion is only available if a script has been installed properly,

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

line 14why, one step back
14and not executed through the ``python`` command. For information about

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

line 15why, one step back
15how to do that, see :ref:`setuptools-integration`. Also, Click currently

Documentation fixesKevin Yapbefore adoption67523af

line 16why, one step back
16only supports completion for Bash.

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

line 17why, one step back
17

Documentation fixesKevin Yapbefore adoption67523af

line 18why, one step back
18Currently, Bash completion is an internal feature that is not customizable.

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 19–23why, one step back
19This might be relaxed in future versions.
2021What it Completes22-----------------23

Documentation fixesKevin Yapbefore adoption67523af

line 24why, one step back
24Generally, the Bash completion support will complete subcommands and

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 25–28why, one step back
25parameters. Subcommands are always listed whereas parameters only if at
26least a dash has been provided. Example::2728 $ repo <TAB><TAB>

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

line 29why, one step back
29 clone commit copy delete setuser

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

line 30why, one step back
30 $ repo clone -<TAB><TAB>

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

line 31why, one step back
31 --deep --help --rev --shallow -r

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 32–35why, one step back
32
33Activation34----------35

Documentation fixesKevin Yapbefore adoption67523af

line 36why, one step back
36In order to activate Bash completion, you need to inform Bash that

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

line 37why, one step back
37completion is available for your script, and how. Any Click application

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

line 38why, one step back
38automatically provides support for that. The general way this works is

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

line 39why, one step back
39through a magic environment variable called ``_<PROG_NAME>_COMPLETE``,

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 40–42why, one step back
40where ``<PROG_NAME>`` is your application executable name in uppercase
41with dashes replaced by underscores.42

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

line 43why, one step back
43If your tool is called ``foo-bar``, then the magic variable is called

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 44–46why, one step back
44``_FOO_BAR_COMPLETE``. By exporting it with the ``source`` value it will
45spit out the activation script which can be trivally activated.46

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

line 47why, one step back
47For instance, to enable Bash completion for your ``foo-bar`` script, this

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 48–51why, one step back
48is what you would need to put into your ``.bashrc``::
4950 eval "$(_FOO_BAR_COMPLETE=source foo-bar)"51

Documentation fixesKevin Yapbefore adoption67523af

line 52why, one step back
52From this point onwards, your script will have Bash completion enabled.

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 53–58why, one step back
53
54Activation Script55-----------------5657The above activation example will always invoke your application on58startup. This might be slowing down the shell activation time

Documentation fixesKevin Yapbefore adoption67523af

lines 59–60why, one step back
59significantly if you have many applications. Alternatively, you could also
60ship a file with the contents of that, which is what Git and other systems

progressbar: add automatic full-width modeArmin Ronacherbefore adoptioncf8f1b7

lines 61–69why, one step back
61are 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