diff --git a/click_completion/bash-click8.j2 b/click_completion/bash-click8.j2 new file mode 100644 index 0000000..2a0e85a --- /dev/null +++ b/click_completion/bash-click8.j2 @@ -0,0 +1 @@ +eval "$(_{{prog_name.upper()}}_COMPLETE=bash_source {{prog_name}})" diff --git a/click_completion/core.py b/click_completion/core.py index 867085e..22dde1e 100644 --- a/click_completion/core.py +++ b/click_completion/core.py @@ -3,6 +3,7 @@ from __future__ import print_function, absolute_import +import distutils import os import re import shlex @@ -303,7 +304,15 @@ def get_code(shell=None, prog_name=None, env_name=None, extra_env=None): env_name = env_name or '_%s_COMPLETE' % prog_name.upper().replace('-', '_') extra_env = extra_env if extra_env else {} env = Environment(loader=FileSystemLoader(os.path.dirname(__file__))) - template = env.get_template('%s.j2' % shell.name) + + click_ver = distutils.version.StrictVersion(click.__version__) + click8_ver = distutils.version.StrictVersion('8.0.0') + if click_ver >= click8_ver: + template_name = '%s-click8.j2' + else: + template_name = '%s.j2' + template = env.get_template(template_name % shell.name) + return template.render(prog_name=prog_name, complete_var=env_name, extra_env=extra_env) diff --git a/click_completion/fish-click8.js b/click_completion/fish-click8.js new file mode 100644 index 0000000..4bda58f --- /dev/null +++ b/click_completion/fish-click8.js @@ -0,0 +1 @@ +eval (env _{{prog_name.upper()}}_COMPLETE=fish_source {{prog_name}}) diff --git a/click_completion/zsh-click8.j2 b/click_completion/zsh-click8.j2 new file mode 100644 index 0000000..e2d07d9 --- /dev/null +++ b/click_completion/zsh-click8.j2 @@ -0,0 +1,7 @@ +#compdef {{prog_name}} +_{{prog_name}}() { + eval "$(_{{prog_name.upper()}}_COMPLETE=zsh_source {{prog_name}})" +} +if [[ "$(basename -- ${(%):-%x})" != "_{{prog_name}}" ]]; then + compdef _{{prog_name}} {{prog_name}} +fi