diff --git a/src/lib.rs b/src/lib.rs index a409474..93384e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,18 +37,22 @@ pub fn is_macos_or_linux() -> bool { is_macos() || is_linux() } -pub fn get_home() -> Option { +pub fn get_home_str() -> Option { match is_macos_or_linux() { true => env::var("HOME").ok(), false => None, } } +pub fn get_home_path() -> Option { + Some(PathBuf::from(get_home_str()?)) +} + pub fn get_absolute_path(path: &str) -> Option { if path == "~" { - return Some(PathBuf::from(get_home()?)); + return Some(PathBuf::from(get_home_str()?)); } else if path.starts_with("~/") { - return Some(PathBuf::from(&format!("{}/{}", get_home()?, &path[2..]))); + return Some(PathBuf::from(&format!("{}/{}", get_home_str()?, &path[2..]))); } fs::canonicalize(path).ok() }