split PATH using split_paths for cross-platform

pull/12883/head
johannes 2025-03-23 18:42:47 +01:00
parent 28349fb8cf
commit 19a245564d
1 changed files with 5 additions and 3 deletions

View File

@ -682,9 +682,11 @@ pub mod completers {
pub fn program(_editor: &Editor, input: &str) -> Vec<Completion> { pub fn program(_editor: &Editor, input: &str) -> Vec<Completion> {
static PROGRAMS_IN_PATH: Lazy<Vec<String>> = Lazy::new(|| { static PROGRAMS_IN_PATH: Lazy<Vec<String>> = Lazy::new(|| {
// Go through the entire PATH and read all files into a vec. // Go through the entire PATH and read all files into a vec.
let mut vec = std::env::var("PATH") let Some(path) = std::env::var_os("PATH") else {
.unwrap_or("".to_owned()) return Vec::new();
.split(":") };
let mut vec = std::env::split_paths(&path)
.flat_map(|s| { .flat_map(|s| {
std::fs::read_dir(s) std::fs::read_dir(s)
.map_or_else(|_| vec![], |res| res.into_iter().collect::<Vec<_>>()) .map_or_else(|_| vec![], |res| res.into_iter().collect::<Vec<_>>())