From 999425d4b8b83430e5161280ae0cd6d0d8e35f30 Mon Sep 17 00:00:00 2001 From: nuid64 <91177333+nuid64@users.noreply.github.com> Date: Wed, 28 Jun 2023 11:37:31 +0000 Subject: [PATCH 1/2] Fix unquoting arguments before passing to shell --- helix-term/src/commands/typed.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 5198e5bdf5cf..136fd090155c 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2154,7 +2154,10 @@ fn run_shell_command( } let shell = cx.editor.config().shell.clone(); - let args = args.join(" "); + let args = args.into_iter() + .map(|arg| format!("'{}'", arg.trim())) + .collect::>() + .join(" "); let callback = async move { let (output, success) = shell_impl_async(&shell, &args, None).await?; From 45279f267f7e1889a7ec99ed7ded6dd4ece6a815 Mon Sep 17 00:00:00 2001 From: nuid32 Date: Fri, 30 Jun 2023 20:19:01 +0000 Subject: [PATCH 2/2] Pass arguments to shell without processing --- helix-term/src/commands/typed.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 136fd090155c..c82a880c4b46 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2154,10 +2154,7 @@ fn run_shell_command( } let shell = cx.editor.config().shell.clone(); - let args = args.into_iter() - .map(|arg| format!("'{}'", arg.trim())) - .collect::>() - .join(" "); + let args = args.join(" "); let callback = async move { let (output, success) = shell_impl_async(&shell, &args, None).await?; @@ -2945,8 +2942,16 @@ pub(super) fn command_mode(cx: &mut Context) { let shellwords = Shellwords::from(input); let args = shellwords.words(); - if let Err(e) = (cmd.fun)(cx, &args[1..], event) { - cx.editor.set_error(format!("{}", e)); + if cmd.name == "run-shell-command" { + // Pass all input except command + let (_, shell_input) = input.split_once(' ').unwrap_or((input, "")); + if let Err(e) = (cmd.fun)(cx, &[Cow::from(shell_input)], event) { + cx.editor.set_error(format!("{}", e)); + } + } else { + if let Err(e) = (cmd.fun)(cx, &args[1..], event) { + cx.editor.set_error(format!("{}", e)); + } } } else if event == PromptEvent::Validate { cx.editor