Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-stdx/src/env.rs')
| -rw-r--r-- | helix-stdx/src/env.rs | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/helix-stdx/src/env.rs b/helix-stdx/src/env.rs index 9e7781a0..b3f46c25 100644 --- a/helix-stdx/src/env.rs +++ b/helix-stdx/src/env.rs @@ -1,4 +1,3 @@ -//! Functions for working with the host environment. use std::{ borrow::Cow, ffi::{OsStr, OsString}, @@ -11,9 +10,9 @@ use once_cell::sync::Lazy; // We keep the CWD as a static so that we can access it in places where we don't have access to the Editor static CWD: RwLock<Option<PathBuf>> = RwLock::new(None); -/// Get the current working directory. -/// This information is managed internally as the call to std::env::current_dir -/// might fail if the cwd has been deleted. +// Get the current working directory. +// This information is managed internally as the call to std::env::current_dir +// might fail if the cwd has been deleted. pub fn current_working_dir() -> PathBuf { if let Some(path) = &*CWD.read().unwrap() { return path.clone(); @@ -38,7 +37,6 @@ pub fn current_working_dir() -> PathBuf { cwd } -/// Update the current working directory. pub fn set_current_working_dir(path: impl AsRef<Path>) -> std::io::Result<Option<PathBuf>> { let path = crate::path::canonicalize(path); std::env::set_current_dir(&path)?; @@ -47,17 +45,14 @@ pub fn set_current_working_dir(path: impl AsRef<Path>) -> std::io::Result<Option Ok(cwd.replace(path)) } -/// Checks if the given environment variable is set. pub fn env_var_is_set(env_var_name: &str) -> bool { std::env::var_os(env_var_name).is_some() } -/// Checks if a binary with the given name exists. pub fn binary_exists<T: AsRef<OsStr>>(binary_name: T) -> bool { which::which(binary_name).is_ok() } -/// Attempts to find a binary of the given name. See [which](https://linux.die.net/man/1/which). pub fn which<T: AsRef<OsStr>>( binary_name: T, ) -> Result<std::path::PathBuf, ExecutableNotFoundError> { @@ -85,7 +80,7 @@ fn find_brace_end(src: &[u8]) -> Option<usize> { None } -fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option<OsString>) -> Cow<'_, OsStr> { +fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option<OsString>) -> Cow<OsStr> { use regex_automata::meta::Regex; static REGEX: Lazy<Regex> = Lazy::new(|| { @@ -157,7 +152,7 @@ fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option<OsString>) /// * `${<var>:-<default>}`, `${<var>-<default>}` /// * `${<var>:=<default>}`, `${<var>=default}` /// -pub fn expand<S: AsRef<OsStr> + ?Sized>(src: &S) -> Cow<'_, OsStr> { +pub fn expand<S: AsRef<OsStr> + ?Sized>(src: &S) -> Cow<OsStr> { expand_impl(src.as_ref(), |var| std::env::var_os(var)) } |