Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve auto completion for an arbitrary name using a given external script #296

Merged
merged 5 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ or create new completion file, e.g::

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

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 and whenever the application is called the registered external argcomplete script is used for auto completion.

This option can also be used in combination with the other supported shells.

Python Support
--------------
Argcomplete requires Python 2.7 or 3.5+.
Expand Down
14 changes: 9 additions & 5 deletions argcomplete/shell_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
fi
}

_python_argcomplete() {
_python_argcomplete%(function_suffix)s() {
local IFS=$'\013'
local SUPPRESS_SPACE=0
if compopt +o nospace 2> /dev/null; then
Expand All @@ -36,7 +36,7 @@
compopt -o nospace
fi
}
complete %(complete_opts)s -F _python_argcomplete %(executables)s
complete %(complete_opts)s -F _python_argcomplete%(function_suffix)s %(executables)s
'''

tcshcode = '''\
Expand Down Expand Up @@ -86,10 +86,14 @@ def shellcode(executables, use_defaults=True, shell='bash', complete_arguments=N
if shell == 'bash':
quoted_executables = [quote(i) for i in executables]
executables_list = " ".join(quoted_executables)
if not argcomplete_script:
argcomplete_script = '$1'
script = argcomplete_script
if script:
function_suffix = '_' + script
else:
script = '$1'
function_suffix = ''
code = bashcode % dict(complete_opts=complete_options, executables=executables_list,
argcomplete_script=argcomplete_script)
argcomplete_script=script, function_suffix=function_suffix)
else:
code = ""
for executable in executables:
Expand Down