From 36309b72faa70c3497965766742ed144a0205238 Mon Sep 17 00:00:00 2001 From: Christoph Jabs Date: Tue, 12 Mar 2024 10:57:11 +0200 Subject: [PATCH] allow command aliases with arguments note: only aliases that do not contain spaces can be used with arguments since either the entire command or only the first word are checked against the aliases --- src/commands/command_line.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs index d4238353e..5f9d0ded0 100644 --- a/src/commands/command_line.rs +++ b/src/commands/command_line.rs @@ -22,12 +22,20 @@ pub fn read_and_execute( .suffix(suffix) .get_input(backend, context, &mut listener); - if let Some(s) = user_input { + if let Some(mut s) = user_input { let mut trimmed = s.trim_start(); let _ = context.commandline_context_mut().history_mut().add(trimmed); + let (command, arg) = match trimmed.find(' ') { + Some(i) => (&trimmed[..i], &trimmed[i..]), + None => (trimmed, ""), + }; + if let Some(alias) = context.config_ref().cmd_aliases.get(trimmed) { trimmed = alias; + } else if let Some(alias) = context.config_ref().cmd_aliases.get(command) { + s.replace_range(..s.len() - arg.len(), alias); + trimmed = &s; } let command = Command::from_str(trimmed)?;