mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-01 01:36:32 +03:00
feat: add ya.quote()
function instead of ya.shell_join()
This commit is contained in:
parent
d754044aae
commit
19791d8328
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -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",
|
||||
|
@ -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" ] }
|
||||
|
@ -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::<mlua::String>() {
|
||||
s.push_str(shell_words::quote(v?.to_str()?).as_ref());
|
||||
s.push(' ');
|
||||
}
|
||||
s.pop();
|
||||
Ok(s)
|
||||
})?,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user