diff --git a/src/function.rs b/src/function.rs index b7e03e5553..b44bfd72ef 100644 --- a/src/function.rs +++ b/src/function.rs @@ -21,6 +21,7 @@ pub(crate) fn get(name: &str) -> Option { let function = match name { "absolute_path" => Unary(absolute_path), "arch" => Nullary(arch), + "addprefix" => Binary(addprefix), "blake3" => Unary(blake3), "blake3_file" => Unary(blake3_file), "canonicalize" => Unary(canonicalize), @@ -255,6 +256,16 @@ fn invocation_directory_native(context: &FunctionContext) -> Result Result { + Ok( + base + .split(" ") + .map(|s| format!("{pref}{s}")) + .collect::>() + .join(" "), + ) +} + fn join( _context: &FunctionContext, base: &str, diff --git a/tests/functions.rs b/tests/functions.rs index 2c0e814340..a5f9f806de 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -481,6 +481,20 @@ fn trim_end() { assert_eval_eq("trim_end(' f ')", " f"); } +#[test] +fn addprefix() { + assert_eval_eq("addprefix('8', 'r s t')", "8r 8s 8t"); + assert_eval_eq( + "addprefix('src/', 'main sar x11')", + "src/main src/sar src/x11", + ); + assert_eval_eq("addprefix('-', 'c v h y')", "-c -v -h -y"); + assert_eval_eq( + "addprefix('0000', '11 10 01 00')", + "000011 000010 000001 000000", + ); +} + #[test] #[cfg(not(windows))] fn join() {