Do not use -c in cmd.exe (#524)

This commit is contained in:
Denis Isidoro 2021-04-19 07:06:34 -03:00 committed by GitHub
parent 2266c1bc75
commit 53b1d6e7a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 19 deletions

View file

@ -26,7 +26,7 @@ fn prompt_finder(
env_var::remove(env_var::PREVIEW_DELIMITER);
env_var::remove(env_var::PREVIEW_MAP);
let mut extra_preview = None;
let mut extra_preview: Option<String> = None;
let (suggestions, initial_opts) = if let Some(s) = suggestion {
let (suggestion_command, suggestion_opts) = s;
@ -42,13 +42,12 @@ fn prompt_finder(
env_var::set(env_var::PREVIEW_MAP, m);
}
if let Some(p) = &sopts.preview {
extra_preview = Some(format!(";echo;{}", p));
extra_preview = Some(p.into());
}
}
let child = shell::command()
let child = shell::out()
.stdout(Stdio::piped())
.arg("-c")
.arg(&suggestion_command)
.spawn()
.map_err(|e| ShellSpawnError::new(suggestion_command, e))?;
@ -79,7 +78,7 @@ fn prompt_finder(
let exe = fs::exe_string()?;
let extra = extra_preview.clone().unwrap_or_default();
let preview = if cfg!(target_os = "macos") {
let preview = if cfg!(target_os = "windows") {
format!(
r#"(@echo.{{+}}{eof}{{q}}{eof}{name}){eof}{extra} | {exe} preview-var-stdin"#,
exe = exe,
@ -217,8 +216,7 @@ pub fn act(
clipboard::copy(interpolated_snippet)?;
}
_ => {
shell::command()
.arg("-c")
shell::out()
.arg(&interpolated_snippet[..])
.spawn()
.map_err(|e| ShellSpawnError::new(&interpolated_snippet[..], e))?

View file

@ -4,8 +4,7 @@ use anyhow::Result;
pub fn map_expand() -> Result<()> {
let cmd = r#"sed -e 's/^.*$/"&"/' | tr '\n' ' '"#;
shell::command()
.arg("-c")
shell::out()
.arg(cmd)
.spawn()
.map_err(|e| ShellSpawnError::new(cmd, e))?

View file

@ -19,8 +19,7 @@ _copy() {
fi
}"#;
shell::command()
.arg("-c")
shell::out()
.arg(
format!(
r#"{cmd}

View file

@ -23,8 +23,7 @@ echo "$_navi_input" | _navi_map_fn"#,
eof = EOF
);
let output = shell::command()
.arg("-c")
let output = shell::out()
.arg(cmd.as_str())
.stderr(Stdio::inherit())
.output()

View file

@ -15,8 +15,7 @@ pub fn main() -> Result<()> {
if let Some(extra) = parts.next() {
if !extra.is_empty() {
shell::command()
.arg("-c")
shell::out()
.arg(extra)
.spawn()
.map_err(|e| ShellSpawnError::new(extra, e))?

View file

@ -34,8 +34,13 @@ impl ShellSpawnError {
}
}
pub fn command() -> Command {
Command::new(CONFIG.shell())
pub fn out() -> Command {
let shell = CONFIG.shell();
let mut cmd = Command::new(&shell);
if shell != "cmd.exe" {
cmd.arg("-c");
}
cmd
}
pub fn widget_last_command() -> Result<()> {

View file

@ -34,8 +34,7 @@ _open_url "$url""#,
url = url,
eof = EOF,
);
shell::command()
.arg("-c")
shell::out()
.arg(cmd.as_str())
.spawn()
.map_err(|e| ShellSpawnError::new(cmd, e))?