mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-29 08:30:04 +08:00
add resolve_file_path
This commit is contained in:
@@ -17,6 +17,17 @@ pub fn get_home_str() -> Option<String> {
|
|||||||
iff!(util_os::is_macos_or_linux(), env::var("HOME").ok(), None)
|
iff!(util_os::is_macos_or_linux(), env::var("HOME").ok(), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resolve_file_path(path: &str) -> String {
|
||||||
|
let home_path = match get_home_str() {
|
||||||
|
Some(p) => p, None => return path.to_owned(),
|
||||||
|
};
|
||||||
|
match path {
|
||||||
|
"~" => home_path,
|
||||||
|
p if p.starts_with("~/") => home_path + &path.chars().skip(1).collect::<String>(),
|
||||||
|
p => p.to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_home_path() -> Option<PathBuf> {
|
pub fn get_home_path() -> Option<PathBuf> {
|
||||||
Some(PathBuf::from(get_home_str()?))
|
Some(PathBuf::from(get_home_str()?))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user