From 1358fc3ceff6b56afb4ce8bf8fd1a0df4cb99f19 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 19 Jul 2022 10:21:43 +0200 Subject: [PATCH] Deduplicate functions for completing alias names "complete_alias_name" is a better name then "complete_alias" because it's consistent with more similar names, which are: complete_client_name complete_command_name complete_module_name complete_option_name complete_register_name complete_scope complete_face --- src/commands.cc | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 3462822c..812d8b19 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -205,14 +205,6 @@ static Completions complete_command_name(const Context& context, CompletionFlags context, prefix.substr(0, cursor_pos)); } -static Completions complete_alias_name(const Context& context, CompletionFlags, - StringView prefix, ByteCount cursor_pos) -{ - return { 0_byte, cursor_pos, complete(prefix, cursor_pos, - context.aliases().flatten_aliases() - | transform(&HashItem::key)) }; -} - struct ShellScriptCompleter { ShellScriptCompleter(String shell_script, @@ -1332,6 +1324,14 @@ const CommandDesc define_command_cmd = { define_command }; +static Completions complete_alias_name(const Context& context, CompletionFlags, + StringView prefix, ByteCount cursor_pos) +{ + return { 0_byte, cursor_pos, complete(prefix, cursor_pos, + context.aliases().flatten_aliases() + | transform(&HashItem::key))}; +} + const CommandDesc alias_cmd = { "alias", nullptr, @@ -1350,14 +1350,6 @@ const CommandDesc alias_cmd = { } }; -static Completions complete_alias(const Context& context, CompletionFlags flags, - StringView prefix, ByteCount cursor_pos) -{ - return {0_byte, cursor_pos, - complete(prefix, cursor_pos, context.aliases().flatten_aliases() | - transform([](auto& entry) -> const String& { return entry.key; }))}; -} - const CommandDesc unalias_cmd = { "unalias", nullptr, @@ -1366,7 +1358,7 @@ const CommandDesc unalias_cmd = { ParameterDesc{{}, ParameterDesc::Flags::None, 2, 3}, CommandFlags::None, CommandHelper{}, - make_completer(complete_scope, complete_alias, complete_command_name), + make_completer(complete_scope, complete_alias_name, complete_command_name), [](const ParametersParser& parser, Context& context, const ShellContext&) { AliasRegistry& aliases = get_scope(parser[0], context).aliases();