File: README.rst

package info (click to toggle)
python-argcomplete 3.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 704 kB
  • sloc: python: 2,814; makefile: 50; sh: 7
file content (65 lines) | stat: -rw-r--r-- 3,377 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Git Bash Support
----------------
Due to limitations of file descriptor inheritance on Windows, Git Bash not supported out of the box. You can opt in to
using temporary files instead of file descriptors for for IPC by setting the environment variable
``ARGCOMPLETE_USE_TEMPFILES``, e.g. by adding ``export ARGCOMPLETE_USE_TEMPFILES=1`` to ``~/.bashrc``.

For full support, consider using Bash with the Windows Subsystem for Linux (WSL).

Fish Support
------------
To activate completions for fish use::

    register-python-argcomplete --shell fish my-awesome-script | source

or create new completion file, e.g::

    register-python-argcomplete --shell fish my-awesome-script > ~/.config/fish/completions/my-awesome-script.fish

If the script is called using a path, such as ``./my-awesome-script``, it must be registered using the absolute path to the script. ::

    register-python-argcomplete --shell fish $(realpath ./my-awesome-script) > ~/.config/fish/completions/my-awesome-script.fish

The completions using a path will not be automatically loaded since the command name does not match the file name. To load the completions, ``source`` them. ::

    source ~/.config/fish/completions/my-awesome-script.fish

Completion Description For Fish
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default help string is added as completion description.

.. image:: ../docs/fish_help_string.png

You can disable this feature by removing ``_ARGCOMPLETE_DFS`` variable, e.g::

    register-python-argcomplete --shell fish my-awesome-script | grep -v _ARGCOMPLETE_DFS | source

PowerShell Support
------------------
To activate completions for PowerShell use::

    register-python-argcomplete --shell powershell my-awesome-script | Out-String | Invoke-Expression

or create new completion file, e.g::

    register-python-argcomplete --shell powershell my-awesome-script > ~/my-awesome-script.psm1

To activate this completions file, add the below line in ``$PROFILE``. The simplest way is to run ``notepad $PROFILE`` in PowerShell and edit the file. For more information, see `How to create your profile <https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.3#how-to-create-a-profile>`_ and `Profiles and execution policy <https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.3#profiles-and-execution-policy>`_. ::

    Import-Module  "~/my-awesome-script.psm1"

Xonsh support
-------------
The third-party `xontrib-argcomplete <https://github.com/anki-code/xontrib-argcomplete>`_ project provides support for
argcomplete in the `xonsh <https://github.com/xonsh/xonsh>`_ shell.

External argcomplete script
---------------------------
To register an argcomplete script for an arbitrary name, the ``--external-argcomplete-script`` argument of the
``register-python-argcomplete`` script can be used::

    eval "$(register-python-argcomplete --external-argcomplete-script /path/to/script arbitrary-name)"

This allows, for example, to use the auto completion functionality of argcomplete for an application not written in
Python. The command line interface of this program must be additionally implemented in a Python script with argparse and
argcomplete; whenever the application is called, the registered external argcomplete script is used for autocompletion.