diff --git a/Cargo.lock b/Cargo.lock index f5acdfa3..a738821c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1733,6 +1733,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shell-escape" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f" + [[package]] name = "shell-words" version = "1.1.0" @@ -2760,6 +2766,7 @@ dependencies = [ "ratatui", "serde", "serde_json", + "shell-escape", "shell-words", "syntect", "tokio", diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index 35bce019..0f5fe645 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -24,6 +24,7 @@ parking_lot = "^0" ratatui = "^0" serde = "^1" serde_json = "^1" +shell-escape = "^0" shell-words = "^1" syntect = { version = "^5", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] } tokio = { version = "^1", features = [ "parking_lot", "rt-multi-thread" ] } diff --git a/yazi-plugin/src/utils/text.rs b/yazi-plugin/src/utils/text.rs index 87877293..a914e501 100644 --- a/yazi-plugin/src/utils/text.rs +++ b/yazi-plugin/src/utils/text.rs @@ -8,6 +8,17 @@ use super::Utils; impl Utils { pub(super) fn text(lua: &Lua, ya: &Table) -> mlua::Result<()> { + ya.set( + "quote", + lua.create_function(|_, s: mlua::String| { + #[cfg(unix)] + let s = shell_escape::unix::escape(s.to_str()?.into()); + #[cfg(windows)] + let s = shell_escape::windows::escape(s.to_str()?.into()); + Ok(s.into_owned()) + })?, + )?; + ya.set( "truncate", lua.create_function(|_, (text, max): (mlua::String, usize)| { @@ -35,19 +46,6 @@ 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(()) } }