From 9be715045b7e0389d78db217835b97a1c799e62e Mon Sep 17 00:00:00 2001 From: Max Timkovich Date: Sat, 27 May 2023 01:05:24 -0500 Subject: [PATCH] Switch to using shell-words and Exec::cmd for rename-command parsing. --- Cargo.lock | 9 +-------- Cargo.toml | 1 - src/main.rs | 17 ++++++++--------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51c4460..e1c8db5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -359,7 +359,7 @@ checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" [[package]] name = "pipe-rename" -version = "1.6.3" +version = "1.6.4" dependencies = [ "ansi_term", "anyhow", @@ -370,7 +370,6 @@ dependencies = [ "predicates 1.0.8", "serde", "serde_json", - "shell-escape", "shell-words", "subprocess", "tempfile", @@ -543,12 +542,6 @@ dependencies = [ "serde", ] -[[package]] -name = "shell-escape" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f" - [[package]] name = "shell-words" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 4f5ea26..1dcf316 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ shell-words = "1.0.0" tempfile = "3.1.0" dialoguer = "0.6.2" ansi_term = "0.12.1" -shell-escape = "0.1.5" diff = "0.1.12" wild = "2" serde = { version = "1.0.152", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index 8bc8545..d445d15 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ use clap::Parser; use anyhow::{bail, Context}; use dialoguer::Select; use serde::{Deserialize, Serialize}; -use shell_escape::escape; use std::env; use std::fmt::{Display, Formatter}; use std::fs; @@ -273,7 +272,7 @@ fn check_input_files(input_files: &[String]) -> anyhow::Result<()> { println!("{}", Colour::Red.paint(file)); } println!(); - bail!("Nonexisting input files. Aborting."); + bail!("Nonexistent input files. Aborting."); } Ok(()) @@ -307,13 +306,13 @@ fn execute_renames( ) -> anyhow::Result<()> { for replacement in replacements { if let Some(ref cmd) = rename_command { - subprocess::Exec::shell(format!( - "{} {} {}", - cmd, - escape(replacement.original.to_string_lossy()), - escape(replacement.new.to_string_lossy()) - )) - .join()?; + let cmd_parsed = shell_words::split(cmd) + .expect("failed to parse command line flags in rename command"); + subprocess::Exec::cmd(&cmd_parsed[0]) + .args(&cmd_parsed[1..]) + .arg(&replacement.original) + .arg(&replacement.new) + .join()?; } else { match fs::rename(&replacement.original, &replacement.new) { Ok(()) => (),