Skip to content
Myr

Use Python sorting order for ZSH completions. Fixes #1047.

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

authored by Nicholas Wiles · committed by David Lord · parent be28b6c · Browse files · 3 files+30 added−9 removed
This commit

State

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

Diff stats

3 files+30 added−9 removed

  • other:+30 added−9 removed

3 files+30 added−9 removed

modified:click/_bashcomplete.py+18 added-4 removed
8 unmodified lines
9from .types import Choice1011WORDBREAK = '='1213# Note, only BASH version 4.4 and later have the nosort option.14COMPLETION_SCRIPT_BASH = '''15%(complete_func)s() {16 local IFS=$'\n'17 COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \\
1 unmodified line
19 %(autocomplete_var)s=complete $1 ) )20 return 021}2223%(complete_func)setup() {24 local COMPLETION_OPTIONS=""25 local BASH_VERSION_ARR=(${BASH_VERSION//./ })26 if [ ${BASH_VERSION_ARR[0]} -ge 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ];then27 COMPLETION_OPTIONS="-o nosort"28 fi2922complete -F %(complete_func)s %(script_names)s30 complete $COMPLETION_OPTIONS -F %(complete_func)s %(script_names)s31}3233%(complete_func)setup34'''3536COMPLETION_SCRIPT_ZSH = '''37%(complete_func)s() {
13 unmodified lines
51 fi52 done5354 if [ -n "$completions_with_descriptions" ]; then44 _describe '' completions_with_descriptions55 _describe -V unsorted completions_with_descriptions -U -Q56 fi5758 if [ -n "$completions" ]; then47 compadd -M 'r:|=* l:|=* r:|=*' -a completions59 compadd -U -V unsorted -Q -a completions60 fi61 compstate[insert]="automenu"62}6364compdef %(complete_func)s %(script_names)s65'''
178 unmodified lines
244 if is_incomplete_argument(ctx.params, param):245 return get_user_autocompletions(ctx, all_args, incomplete, param)246247 add_subcommand_completions(ctx, incomplete, completions)235 return completions248 # Sort before returning so that proper ordering can be enforced in custom types.249 return sorted(completions)250251252def do_complete(cli, prog_name, include_descriptions):253 cwords = split_arg_string(os.environ['COMP_WORDS'])
24 unmodified lines
modified:examples/bashcompletion/bashcompletion.py+9 added-5 removed
6 unmodified lines
7 pass8910def get_env_vars(ctx, args, incomplete):11 # Completions returned as strings do not have a description displayed.12 for key in os.environ.keys():13 if incomplete in key:14 yield key15
10 unmodified lines
26 pass272829def list_users(ctx, args, incomplete):29 # Here you can generate completions dynamically30 users = ['bob', 'alice']31 for user in users:32 if user.startswith(incomplete):33 yield user30 # You can generate completions with descriptions by returning31 # tuples in the form (completion, description).32 users = [('bob', 'butcher'),33 ('alice', 'baker'),34 ('jerry', 'candlestick maker')]35 # Ths will allow completion matches based on matches within the description string too!36 return [user for user in users if incomplete in user[0] or incomplete in user[1]]373839@group.command(help='Choose a user')40@click.argument("user", type=click.STRING, autocompletion=list_users)41def subcmd(user):42 click.echo('Chosen user is %s' % user)434445cli.add_command(group)
modified:CHANGES.rst+3 added
79 unmodified lines
80- Fixed issues where ``fd`` was undefined. (`#1007`_)81- Fix formatting for short help. (`#1008`_)82- Document how ``auto_envar_prefix`` works with command groups. (`#1011`_)83- Don't add newlines by default for progress bars. (`#1013`_)84- Use Python sorting order for ZSH completions. (`#1047`_, `#1059`_)85- Document that parameter names are lowercased by default. (`#1055`_)86- Subcommands that are named by the function now automatically have the underscore replaced with a dash. If you register a function named ``my_command`` it becomes ``my-command`` in the command line interface.8788.. _#202: https://github.com/pallets/click/issues/202
101 unmodified lines
190.. _#1016: https://github.com/pallets/click/pull/1016191.. _#1020: https://github.com/pallets/click/pull/1020192.. _#1022: https://github.com/pallets/click/pull/1022193.. _#1027: https://github.com/pallets/click/pull/1027194.. _#1047: https://github.com/pallets/click/pull/1047195.. _#1055: https://github.com/pallets/click/pull/1055196.. _#1059: https://github.com/pallets/click/pull/1059197198199Version 6.7200-----------
343 unmodified lines