diff --git a/src/lib.rs b/src/lib.rs index 4d8b3d1..c5a2c78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,10 @@ extern crate term; use std::{ + env, + fs, io::{self, Write, Error, ErrorKind}, + path::PathBuf, process::Command, }; @@ -34,6 +37,19 @@ pub fn is_macos_or_linux() -> bool { is_macos() || is_linux() } +pub fn get_home() -> Option { + env::var("HOME").ok() +} + +pub fn get_absolute_path(path: &str) -> Option { + if path == "~" { + return Some(PathBuf::from(get_home()?)); + } else if path.starts_with("~/") { + return Some(PathBuf::from(&format!("{}/{}", get_home()?, &path[2..]))); + } + fs::canonicalize(path).ok() +} + pub enum MessageType { INFO, OK, WARN, ERROR, } pub fn print_message_ex(color: Option, h: &str, message: &str) {