From 9e113a9337fc3bb271525b41155eb8f90ab29254 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 5 Feb 2024 09:00:48 +0800 Subject: [PATCH] feat: add `ya.shell_join()` API --- yazi-plugin/src/utils/text.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/yazi-plugin/src/utils/text.rs b/yazi-plugin/src/utils/text.rs index 11bb43b2..87877293 100644 --- a/yazi-plugin/src/utils/text.rs +++ b/yazi-plugin/src/utils/text.rs @@ -35,6 +35,19 @@ impl Utils { lua.create_function(|_, mime: mlua::String| Ok(mime_valid(mime.as_bytes())))?, )?; + ya.set( + "shell_join", + lua.create_function(|_, table: Table| { + let mut s = String::new(); + for v in table.sequence_values::() { + s.push_str(shell_words::quote(v?.to_str()?).as_ref()); + s.push(' '); + } + s.pop(); + Ok(s) + })?, + )?; + Ok(()) } }