mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-17 01:18:26 +01:00
add {-} format for exec
This commit is contained in:
parent
b9cb5d54a4
commit
46db1c4ef3
3 changed files with 20 additions and 1 deletions
|
@ -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<str>,
|
||||
{
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue