Skip to content

Commit

Permalink
Use slices instead of iterators for shell invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Omnikar committed Aug 4, 2021
1 parent 0e3fad0 commit 15fc792
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3934,19 +3934,16 @@ fn shell(cx: &mut Context, prompt: &str, pipe: bool, behavior: ShellBehavior) {
use std::io::Write;
use std::process::{Command, Stdio};
let shell = Option::<Vec<_>>::None; // this should come from config, but can't currently
let (shell, args) = match shell {
Some(shell) if !shell.is_empty() => {
let mut args = shell.into_iter();
(args.next().unwrap(), args)
}
let shell = match shell {
Some(v) if !v.is_empty() => v,
_ => {
if cfg!(windows) {
("cmd".to_owned(), vec!["/C".to_owned()].into_iter())
vec!["cmd".to_owned(), "/C".to_owned()]
} else {
(
vec![
std::env::var("SHELL").unwrap_or_else(|_| "sh".to_owned()),
vec!["-c".to_owned()].into_iter(),
)
"-c".to_owned(),
]
}
}
};
Expand All @@ -3960,11 +3957,8 @@ fn shell(cx: &mut Context, prompt: &str, pipe: bool, behavior: ShellBehavior) {
let selection = doc.selection(view.id);
let transaction =
Transaction::change_by_selection(doc.text(), selection, |range| {
let mut command = Command::new(&shell);
for arg in args.as_ref() {
command.arg(arg);
}
let mut process = command
let mut process = Command::new(&shell[0])
.args(&shell[1..])
.arg(input)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
Expand Down

0 comments on commit 15fc792

Please sign in to comment.