Skip to content

Commit

Permalink
Switch to using shell-words and Exec::cmd for rename-command parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtimkovich committed May 27, 2023
1 parent 893710b commit 9be7150
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
17 changes: 8 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(()) => (),
Expand Down

0 comments on commit 9be7150

Please sign in to comment.