aboutsummaryrefslogtreecommitdiff
path: root/helix-stdx
diff options
context:
space:
mode:
authorMichael Davis2024-01-23 14:29:07 +0000
committerBlaž Hrastnik2024-01-24 06:47:49 +0000
commit6d724a8f331f4b2a8f1a001e990cf6129dc50b00 (patch)
treecc2d8c6068ec8ad58aa29320c08c6218b2e8070d /helix-stdx
parent6bfe1ddc53f542d62e242fd4aaf6748dda1b0e71 (diff)
Re-export `which` from `helix-stdx::env`
We use `which::which` in many crates, so `which` was a separate dependency across all of them. We can centralize `which` into the stdx crate so it's easy for all crates to depend on it. I also moved the rest of `helix-view/src/env.rs` into helix-stdx's `env` module since it only contained a thin wrapper around `which` and `std::env`.
Diffstat (limited to 'helix-stdx')
-rw-r--r--helix-stdx/Cargo.toml1
-rw-r--r--helix-stdx/src/env.rs10
2 files changed, 11 insertions, 0 deletions
diff --git a/helix-stdx/Cargo.toml b/helix-stdx/Cargo.toml
index 9b4de9fe..e77f8b91 100644
--- a/helix-stdx/Cargo.toml
+++ b/helix-stdx/Cargo.toml
@@ -15,6 +15,7 @@ homepage.workspace = true
dunce = "1.0"
etcetera = "0.8"
ropey = { version = "1.6.1", default-features = false }
+which = "6.0"
[dev-dependencies]
tempfile = "3.9"
diff --git a/helix-stdx/src/env.rs b/helix-stdx/src/env.rs
index 864ba828..3676727f 100644
--- a/helix-stdx/src/env.rs
+++ b/helix-stdx/src/env.rs
@@ -1,3 +1,5 @@
+pub use which::which;
+
use std::{
path::{Path, PathBuf},
sync::RwLock,
@@ -30,6 +32,14 @@ pub fn set_current_working_dir(path: impl AsRef<Path>) -> std::io::Result<()> {
Ok(())
}
+pub fn env_var_is_set(env_var_name: &str) -> bool {
+ std::env::var_os(env_var_name).is_some()
+}
+
+pub fn binary_exists(binary_name: &str) -> bool {
+ which::which(binary_name).is_ok()
+}
+
#[cfg(test)]
mod tests {
use super::{current_working_dir, set_current_working_dir};