use std::{borrow::Cow, ffi::OsString, path::PathBuf, process::Command};
use anyhow::anyhow;
pub fn full_pwd() -> String {
std::env::current_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap()
}
pub fn top_pwd() -> String {
let cur_dir = std::env::current_dir().unwrap();
let home_dir = dirs::home_dir().unwrap();
if cur_dir == home_dir {
String::from("~")
} else if cur_dir == PathBuf::from("/") {
String::from("/")
} else {
cur_dir
.file_name()
.unwrap()
.to_os_string()
.into_string()
.unwrap()
}
}
pub fn username() -> anyhow::Result<String> {
let username = Command::new("whoami").output()?.stdout;
let encoded = std::str::from_utf8(&username)?
.strip_suffix("\n")
.unwrap()
.to_string();
Ok(encoded)
}
pub fn hostname() -> anyhow::Result<String> {
let username = Command::new("hostname").output()?.stdout;
let encoded = std::str::from_utf8(&username)?
.strip_suffix("\n")
.unwrap()
.to_string();
Ok(encoded)
}
pub fn current_time() {
todo!()
}