Skip to content
Myr

fish completion

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jonathan Lestrelin · committed by David Lord · parent 3592995 · Browse files · 2 files+37 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+37 added−6 removed

  • other:+37 added−6 removed

2 files+37 added−6 removed

modified:click/_bashcomplete.py+31 added-2 removed
71 unmodified lines
7273compdef %(complete_func)s %(script_names)s74'''7576COMPLETION_SCRIPT_FISH = '''77complete --no-files --command %(script_names)s --arguments "(env %(autocomplete_var)s=complete_fish COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(script_names)s)"78'''7980_invalid_ident_char_re = re.compile(r'[^a-zA-Z0-9_]')818283def get_completion_script(prog_name, complete_var, shell):84 cf_name = _invalid_ident_char_re.sub('', prog_name.replace('-', '_'))81 script = COMPLETION_SCRIPT_ZSH if shell == 'zsh' else COMPLETION_SCRIPT_BASH85 if shell == 'zsh':86 script = COMPLETION_SCRIPT_ZSH87 elif shell == 'fish':88 script = COMPLETION_SCRIPT_FISH89 else:90 script = COMPLETION_SCRIPT_BASH91 return (script % {92 'complete_func': '_%s_completion' % cf_name,93 'script_names': prog_name,94 'autocomplete_var': complete_var,
202 unmodified lines
297298 return True299300301def do_complete_fish(cli, prog_name):302 cwords = split_arg_string(os.environ['COMP_WORDS'])303 incomplete = os.environ['COMP_CWORD']304 args = cwords[1:]305 for item in get_choices(cli, prog_name, args, incomplete):306 if item[1]:307 echo("%(arg)s\t%(desc)s" % {'arg': item[0], 'desc': item[1]})308 else:309 echo(item[0])310311 return True312313314def bashcomplete(cli, prog_name, complete_var, complete_instr):315 if complete_instr.startswith('source'):294 shell = 'zsh' if complete_instr == 'source_zsh' else 'bash'316 if complete_instr == 'source_zsh':317 shell = 'zsh'318 elif complete_instr == 'source_fish':319 shell = 'fish'320 else:321 shell = 'bash'322 echo(get_completion_script(prog_name, complete_var, shell))323 return True324 elif complete_instr == 'complete_fish':325 return do_complete_fish(cli, prog_name)326 elif complete_instr == 'complete' or complete_instr == 'complete_zsh':327 return do_complete(cli, prog_name, complete_instr == 'complete_zsh')328 return False
modified:docs/bashcomplete.rst+6 added-4 removed
11 unmodified lines
1213Bash completion is only available if a script has been installed properly,14and not executed through the ``python`` command. For information about15how to do that, see :ref:`setuptools-integration`. Click currently16only supports completion for Bash and Zsh.16only supports completion for Bash, Zsh and Fish.1718What it Completes19-----------------20
33 unmodified lines
54 click.echo('Environment variable: %s' % envvar)55 click.echo('Value: %s' % os.environ[envvar])565758Completion help strings (ZSH only)59----------------------------------58Completion help strings (ZSH/fish only)59---------------------------------------6061ZSH supports showing documentation strings for completions. These are taken61ZSH and fish support showing documentation strings for completions. These are taken62from the help parameters of options and subcommands. For dynamically generated63completions a help string can be provided by returning a tuple instead of a64string. The first element of the tuple is the completion and the second is the65help string to display.
61 unmodified lines
127And then you would put this into your .bashrc or .zshrc instead::128129 . /path/to/foo-bar-complete.sh130131Or for fish, you can just add the file to the completions directory:132133 _FOO_BAR_COMPLETE=source_fish foo-bar > ~/.config/fish/completions/foo-bar-complete.fish