Skip to content
Myr

refactor completion command splitting

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

authored by David Lord · committed by David Lord · parent 792f03f · Browse files · 1 file+27 added−21 removed
This commit

State

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

Diff stats

1 file+27 added−21 removed

  • other:+27 added−21 removed

1 file+27 added−21 removed

modified:click/_bashcomplete.py+27 added-21 removed
75 unmodified lines
76COMPLETION_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_completion_scripts = {81 "bash": COMPLETION_SCRIPT_BASH,82 "zsh": COMPLETION_SCRIPT_ZSH,83 "fish": COMPLETION_SCRIPT_FISH,84}8586_invalid_ident_char_re = re.compile(r'[^a-zA-Z0-9_]')878889def get_completion_script(prog_name, complete_var, shell):90 cf_name = _invalid_ident_char_re.sub('', prog_name.replace('-', '_'))85 if shell == 'zsh':86 script = COMPLETION_SCRIPT_ZSH87 elif shell == 'fish':88 script = COMPLETION_SCRIPT_FISH89 else:90 script = COMPLETION_SCRIPT_BASH91 script = _completion_scripts.get(shell, COMPLETION_SCRIPT_BASH)92 return (script % {93 'complete_func': '_%s_completion' % cf_name,94 'script_names': prog_name,95 'autocomplete_var': complete_var,
196 unmodified lines
292293 for item in get_choices(cli, prog_name, args, incomplete):294 echo(item[0])295 if include_descriptions:295 # ZSH has trouble dealing with empty array parameters when returned from commands, so use a well defined character '_' to indicate no description is present.296 # ZSH has trouble dealing with empty array parameters when297 # returned from commands, use '_' to indicate no description298 # is present.299 echo(item[1] if item[1] else '_')300301 return True302303304def do_complete_fish(cli, prog_name):302 cwords = split_arg_string(os.environ['COMP_WORDS'])303 incomplete = os.environ['COMP_CWORD']305 cwords = split_arg_string(os.environ["COMP_WORDS"])306 incomplete = os.environ["COMP_CWORD"]307 args = cwords[1:]308309 for item in get_choices(cli, prog_name, args, incomplete):310 if item[1]:307 echo("%(arg)s\t%(desc)s" % {'arg': item[0], 'desc': item[1]})311 echo("%(arg)s\t%(desc)s" % {"arg": item[0], "desc": item[1]})312 else:313 echo(item[0])314315 return True316317318def bashcomplete(cli, prog_name, complete_var, complete_instr):315 if complete_instr.startswith('source'):316 if complete_instr == 'source_zsh':317 shell = 'zsh'318 elif complete_instr == 'source_fish':319 shell = 'fish'320 else:321 shell = 'bash'319 if "_" in complete_instr:320 command, shell = complete_instr.split("_", 1)321 else:322 command = complete_instr323 shell = "bash"324325 if command == "source":326 echo(get_completion_script(prog_name, complete_var, shell))327 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 elif command == "complete":329 if shell == "fish":330 return do_complete_fish(cli, prog_name)331 elif shell in {"bash", "zsh"}:332 return do_complete(cli, prog_name, shell == "zsh")333334 return False