on master help sign in
Avoid setting stdin handle when not necessary (#3248)

* Avoid setting stdin handle when not necessary Avoid setting the stdin handle in `shell_impl` when the input argument is None. This permits to run commands with no stdin with :sh * refactoring to avoid code duplication * making clippy happy * Process variable name fix

commit3121353c6ab2fbc5fced28f075c7fc45b53b661e authorDario Oddenino <branch13@gmail.com> dateFri 5 Aug 2022, 04:15 (4 years ago) parentc2a6d29
1 file changed+9−5
helix-term/src/commands.rs+9−5
helix-term/src/commands.rs+9−5
@@ -4552,14 +4552,18 @@ fn shell_impl(
45524552 use std::process::{Command, Stdio};
45534553 ensure!(!shell.is_empty(), "No shell set");
45544554
4555− let mut process = match Command::new(&shell[0])
4555+ let mut process = Command::new(&shell[0]);
4556+ process
45564557 .args(&shell[1..])
45574558 .arg(cmd)
4558− .stdin(Stdio::piped())
45594559 .stdout(Stdio::piped())
4560− .stderr(Stdio::piped())
4561− .spawn()
4562− {
4560+ .stderr(Stdio::piped());
4561+
4562+ if input.is_some() {
4563+ process.stdin(Stdio::piped());
4564+ }
4565+
4566+ let mut process = match process.spawn() {
45634567 Ok(process) => process,
45644568 Err(e) => {
45654569 log::error!("Failed to start shell: {}", e);