mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat(plugins): add Command.which(cmd) function
This commit is contained in:
parent
ef1a31a274
commit
21d4b035b4
3 changed files with 7 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -3398,6 +3398,7 @@ dependencies = [
|
|||
"tracing",
|
||||
"unicode-width 0.2.0",
|
||||
"uzers",
|
||||
"which",
|
||||
"yazi-adapter",
|
||||
"yazi-boot",
|
||||
"yazi-config",
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ tokio-stream = { workspace = true }
|
|||
tokio-util = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
unicode-width = { workspace = true }
|
||||
which = "6.0.3"
|
||||
yazi-prebuild = "0.1.2"
|
||||
|
||||
[target."cfg(unix)".dependencies]
|
||||
|
|
|
|||
|
|
@ -23,12 +23,17 @@ impl Command {
|
|||
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([
|
||||
// Stdio
|
||||
("NULL", NULL),
|
||||
("PIPED", PIPED),
|
||||
("INHERIT", INHERIT),
|
||||
])?;
|
||||
command.raw_set("which", which)?;
|
||||
|
||||
command.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue