mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: add ya.quote() function instead of ya.shell_join()
This commit is contained in:
parent
d754044aae
commit
19791d8328
3 changed files with 19 additions and 13 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -1733,6 +1733,12 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shell-escape"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shell-words"
|
name = "shell-words"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|
@ -2760,6 +2766,7 @@ dependencies = [
|
||||||
"ratatui",
|
"ratatui",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"shell-escape",
|
||||||
"shell-words",
|
"shell-words",
|
||||||
"syntect",
|
"syntect",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ parking_lot = "^0"
|
||||||
ratatui = "^0"
|
ratatui = "^0"
|
||||||
serde = "^1"
|
serde = "^1"
|
||||||
serde_json = "^1"
|
serde_json = "^1"
|
||||||
|
shell-escape = "^0"
|
||||||
shell-words = "^1"
|
shell-words = "^1"
|
||||||
syntect = { version = "^5", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }
|
syntect = { version = "^5", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }
|
||||||
tokio = { version = "^1", features = [ "parking_lot", "rt-multi-thread" ] }
|
tokio = { version = "^1", features = [ "parking_lot", "rt-multi-thread" ] }
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,17 @@ use super::Utils;
|
||||||
|
|
||||||
impl Utils {
|
impl Utils {
|
||||||
pub(super) fn text(lua: &Lua, ya: &Table) -> mlua::Result<()> {
|
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(
|
ya.set(
|
||||||
"truncate",
|
"truncate",
|
||||||
lua.create_function(|_, (text, max): (mlua::String, usize)| {
|
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())))?,
|
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::<mlua::String>() {
|
|
||||||
s.push_str(shell_words::quote(v?.to_str()?).as_ref());
|
|
||||||
s.push(' ');
|
|
||||||
}
|
|
||||||
s.pop();
|
|
||||||
Ok(s)
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue