diff --git a/Cargo.lock b/Cargo.lock index 5f22f17..77d4343 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,6 +193,16 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +[[package]] +name = "users" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" +dependencies = [ + "libc", + "log", +] + [[package]] name = "wasite" version = "0.1.0" @@ -486,5 +496,6 @@ version = "0.1.0" dependencies = [ "colored", "sysinfo", + "users", "whoami", ] diff --git a/Cargo.toml b/Cargo.toml index 96598c6..4a44f85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" [dependencies] colored = "2.1.0" sysinfo = "0.32.0" +users = "0.11.0" whoami = "1.5.2" diff --git a/src/main.rs b/src/main.rs index c75876b..c4510df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ use std::process::Command; use sysinfo::{Components, Disks, Networks, System}; +use colored::*; +use users::{get_user_by_uid, get_current_uid}; static LOGO: &str = "       'xkXxdxddd,oddc. .  'c:           MM0d' :kk' 'ldddx0OkMMMMMMXOxdxKk.   @@ -22,46 +24,64 @@ static LOGO: &str = "     [38  cMMM .XKXMM.  ..,   "; fn main() { - let info_kernel_out = Command::new("uname") + let mut sys = System::new_all(); + sys.refresh_all(); + + let user = get_user_by_uid(get_current_uid()).unwrap(); + + let shell = String::from_utf8( + Command::new("bash").arg("-c").arg("echo $SHELL").output().expect("failed to exec").stdout + ).unwrap().split("/").last().unwrap().trim().to_string(); + + let term = String::from_utf8( + Command::new("bash").arg("-c").arg("echo $TERM").output().expect("failed to exec").stdout + ).unwrap().trim().to_string(); + + let de = String::from_utf8( + Command::new("bash").arg("-c").arg("echo $XDG_CURRENT_DESKTOP").output().expect("failed to exec").stdout + ).unwrap().trim().to_string(); + + let my_pid = sysinfo::get_current_pid().expect("unable to get PID of the current process"); + let parent_pid = sys.process(my_pid).expect("no self process?").parent().expect("unable to get parent process"); + let parent_name = sys.process(parent_pid).expect("unable to get parent process").name().to_str().unwrap().to_string(); + + let info = vec![ + format!(""), + format!("┌────────────"), + //format!("│ {} : {}", "Username ".to_string().truecolor(90, 100, 255), user.name().to_str().unwrap().to_string()), + format!("│ {} : {}", "OS Name ".to_string().truecolor(90, 100, 255), System::name().unwrap()), + format!("│ {} : {}", "Kernel ".to_string().truecolor(90, 100, 255), System::kernel_version().unwrap()), + format!("│ {} : {}", "OS Version".to_string().truecolor(90, 100, 255), System::os_version().unwrap()), + format!("│ {} : {}", "Hostname ".to_string().truecolor(90, 100, 255), System::host_name().unwrap()), + format!("│ {} : {}", "CPU Arch ".to_string().truecolor(90, 100, 255), System::cpu_arch().unwrap()), + format!("│ {} : {}", "CPU Cores ".to_string().truecolor(90, 100, 255), + sys.physical_core_count().unwrap().to_string() + ), + format!("│ {} : {}", "Shell ".to_string().truecolor(90, 100, 255), parent_name), + format!("│ {} : {}", "Terminal ".to_string().truecolor(90, 100, 255), term), + format!("│ {} : {}", "Desktop ".to_string().truecolor(90, 100, 255), de), + format!("│ {} : {}", "Uptime ".to_string().truecolor(90, 100, 255), (|| { + let u_s = System::uptime(); + format!( + "{} Hours {} Minutes {} Seconds", + u_s / 3600, + u_s % 3600 / 60, + u_s % 60 + ) + })()), + format!( + "│ {} : {}MiB / {}MiB", "Memory Use".to_string().truecolor(90, 100, 255), + sys.used_memory() / 1000000, + sys.total_memory() / 1000000 + ), + format!("└────────────") + ]; + + let info_kernel_out = Command::new("uname") .arg("-r") .output() .expect("failed to fetch kernel ver"); let info_kernel = String::from_utf8_lossy(&info_kernel_out.stdout); - - let mut sys = System::new_all(); - sys.refresh_all(); - - let info = vec![ - String::new(), - String::new(), - format!("OS Name : {}", System::name().unwrap()), - format!("Kernel : {}", System::kernel_version().unwrap()), - format!("OS Version : {}", System::os_version().unwrap()), - format!("Hostname : {}", System::host_name().unwrap()), - format!("CPU Arch : {}", System::cpu_arch().unwrap()), - format!( - "CPU Cores : {}", - sys.physical_core_count().unwrap().to_string() - ), - format!( - "Uptime : {}", - (|| { - let u_s = System::uptime(); - format!( - "{} Hours {} Minutes {} Seconds", - u_s / 3600, - u_s % 3600 / 60, - u_s % 60 - ) - })() - ), - format!( - "Memory Use : {}MiB / {}MiB", - sys.used_memory() / 1000000, - sys.total_memory() / 1000000 - ), - ]; - println!("\n"); let binding = String::new();