From 21d4b035b486237c77de893ca8a7b1458152a99c Mon Sep 17 00:00:00 2001 From: shurizzle Date: Sat, 26 Oct 2024 16:18:00 +0200 Subject: [PATCH] feat(plugins): add Command.which(cmd) function --- Cargo.lock | 1 + yazi-plugin/Cargo.toml | 1 + yazi-plugin/src/process/command.rs | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c33b9f4d..2e781822 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3398,6 +3398,7 @@ dependencies = [ "tracing", "unicode-width 0.2.0", "uzers", + "which", "yazi-adapter", "yazi-boot", "yazi-config", diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index d49f9706..61c05eea 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -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] diff --git a/yazi-plugin/src/process/command.rs b/yazi-plugin/src/process/command.rs index f3ff918e..acbdc481 100644 --- a/yazi-plugin/src/process/command.rs +++ b/yazi-plugin/src/process/command.rs @@ -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)])?));