diff --git a/src/exec/mod.rs b/src/exec/mod.rs index 15e1ae5..fd0705d 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -19,6 +19,8 @@ use self::command::execute_command; use self::input::{basename, dirname, remove_extension}; pub use self::job::{batch, job}; use self::token::Token; +use crate::filesystem::strip_current_dir; + /// Execution mode of the command #[derive(Debug, Clone, Copy, PartialEq)] @@ -72,7 +74,7 @@ impl CommandTemplate { S: AsRef, { lazy_static! { - static ref PLACEHOLDER_PATTERN: Regex = Regex::new(r"\{(/?\.?|//)\}").unwrap(); + static ref PLACEHOLDER_PATTERN: Regex = Regex::new(r"\{(/?\.?|//|-)\}").unwrap(); } let mut args = Vec::new(); @@ -98,6 +100,7 @@ impl CommandTemplate { "{/}" => tokens.push(Token::Basename), "{//}" => tokens.push(Token::Parent), "{/.}" => tokens.push(Token::BasenameNoExt), + "{-}" => tokens.push(Token::StripPrefix), _ => unreachable!("Unhandled placeholder"), } @@ -231,6 +234,10 @@ impl ArgumentTemplate { Placeholder => { s.push(Self::replace_separator(path.as_ref(), path_separator)) } + StripPrefix => { + let path = strip_current_dir(path); + s.push(Self::replace_separator(path.as_ref(), path_separator)) + } Text(ref string) => s.push(string), } } diff --git a/src/exec/token.rs b/src/exec/token.rs index 0cf4df3..2e4b913 100644 --- a/src/exec/token.rs +++ b/src/exec/token.rs @@ -11,6 +11,7 @@ pub enum Token { Parent, NoExt, BasenameNoExt, + StripPrefix, Text(String), } @@ -22,6 +23,7 @@ impl Display for Token { Token::Parent => f.write_str("{//}")?, Token::NoExt => f.write_str("{.}")?, Token::BasenameNoExt => f.write_str("{/.}")?, + Token::StripPrefix => f.write_str("{-}")?, Token::Text(ref string) => f.write_str(string)?, } Ok(()) diff --git a/tests/tests.rs b/tests/tests.rs index 8811bf5..185d607 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1363,6 +1363,16 @@ fn test_exec() { ); te.assert_output(&["e1", "--exec", "printf", "%s.%s\n"], "./e1 e2."); + + te.assert_output( + &["foo", "--exec", "echo", "{-}"], + "a.foo + one/b.foo + one/two/C.Foo2 + one/two/c.foo + one/two/three/d.foo + one/two/three/directory_foo", + ); } }