use std::fs; use std::path::Path; /// Refresh the shell's $PATH /// /// This function caches all valid paths within within the directories /// specified. /// /// # Arguments /// * `path` - A reference to a vector that holds a list to the shell $PATHs /// /// # Returns /// * `bins: Vec` - A new cache of all valid file paths in $PATH /// /// # Examples /// ``` /// let path = vec!["/bin"]; /// let path = path.into_iter().map(Path::new).collect(); /// let mut bins = path::refresh(&path); /// ... /// // A situation occurs where the $PATH needs to be refreshed /// bins = path::refresh(&path) /// ``` pub fn refresh(path: &Vec<&Path>) -> Vec { let mut bins: Vec = Vec::new(); for p in path { let files = match fs::read_dir(p) { Ok(files) => files, Err(_) => continue, }; for file in files { bins.push(file.unwrap().path().display().to_string()); } } bins }