feat(plugins): add Command.which(cmd) function

This commit is contained in:
shurizzle 2024-10-26 16:18:00 +02:00
parent ef1a31a274
commit 21d4b035b4
3 changed files with 7 additions and 0 deletions

1
Cargo.lock generated
View file

@ -3398,6 +3398,7 @@ dependencies = [
"tracing", "tracing",
"unicode-width 0.2.0", "unicode-width 0.2.0",
"uzers", "uzers",
"which",
"yazi-adapter", "yazi-adapter",
"yazi-boot", "yazi-boot",
"yazi-config", "yazi-config",

View file

@ -39,6 +39,7 @@ tokio-stream = { workspace = true }
tokio-util = { workspace = true } tokio-util = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
unicode-width = { workspace = true } unicode-width = { workspace = true }
which = "6.0.3"
yazi-prebuild = "0.1.2" yazi-prebuild = "0.1.2"
[target."cfg(unix)".dependencies] [target."cfg(unix)".dependencies]

View file

@ -23,12 +23,17 @@ impl Command {
Ok(Self { inner }) Ok(Self { inner })
})?; })?;
let which = lua.create_function(|_, (program,): (String,)| {
Ok(which::which(program).ok().and_then(|path| path.to_str().map(str::to_string)))
})?;
let command = lua.create_table_from([ let command = lua.create_table_from([
// Stdio // Stdio
("NULL", NULL), ("NULL", NULL),
("PIPED", PIPED), ("PIPED", PIPED),
("INHERIT", INHERIT), ("INHERIT", INHERIT),
])?; ])?;
command.raw_set("which", which)?;
command.set_metatable(Some(lua.create_table_from([("__call", new)])?)); command.set_metatable(Some(lua.create_table_from([("__call", new)])?));