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
Provenance
- Commit
792f03f- Tree
f6a831d- Author
Jonathan Lestrelin <jonathan.lestrelin@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
3592995
2 files changed+37 added−6 removed
modified:click/_bashcomplete.py+31 added-2 removed
71 unmodified lines72 73 compdef %(complete_func)s %(script_names)s74 '''75 76+COMPLETION_SCRIPT_FISH = '''77+complete --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+'''79+80 _invalid_ident_char_re = re.compile(r'[^a-zA-Z0-9_]')81 82 83 def 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 lines297 298 return True299 300 301+def 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])310+311+ return True312+313+314 def 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 Falsemodified:docs/bashcomplete.rst+6 added-4 removed
11 unmodified lines12 13 Bash completion is only available if a script has been installed properly,14 and not executed through the ``python`` command. For information about15 how to do that, see :ref:`setuptools-integration`. Click currently16-only supports completion for Bash and Zsh.16+only supports completion for Bash, Zsh and Fish.17 18 What it Completes19 -----------------20 33 unmodified lines54 click.echo('Environment variable: %s' % envvar)55 click.echo('Value: %s' % os.environ[envvar])56 57 58-Completion help strings (ZSH only)59-----------------------------------58+Completion help strings (ZSH/fish only)59+---------------------------------------60 61-ZSH supports showing documentation strings for completions. These are taken61+ZSH and fish support showing documentation strings for completions. These are taken62 from the help parameters of options and subcommands. For dynamically generated63 completions a help string can be provided by returning a tuple instead of a64 string. The first element of the tuple is the completion and the second is the65 help string to display.61 unmodified lines127 And then you would put this into your .bashrc or .zshrc instead::128 129 . /path/to/foo-bar-complete.sh130 131+Or for fish, you can just add the file to the completions directory:132 133+ _FOO_BAR_COMPLETE=source_fish foo-bar > ~/.config/fish/completions/foo-bar-complete.fish