diff --git a/README.rst b/README.rst index a6eb8a7f..73716378 100644 --- a/README.rst +++ b/README.rst @@ -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+. diff --git a/argcomplete/shell_integration.py b/argcomplete/shell_integration.py index d07e4dca..6016d1ee 100644 --- a/argcomplete/shell_integration.py +++ b/argcomplete/shell_integration.py @@ -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 @@ -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 = '''\ @@ -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: