Merge branch 'iVacon:master' into master
This commit is contained in:
commit
aef1690c1b
1 changed files with 60 additions and 50 deletions
100
src/main.rs
100
src/main.rs
|
@ -7,27 +7,28 @@ use std::env;
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
// User & hostname
|
// User & hostname
|
||||||
let user = Command::new("whoami")
|
// let user = Command::new("whoami")
|
||||||
.output()
|
// .output()
|
||||||
.expect("Failed to get user");
|
// .expect("Failed to get user");
|
||||||
|
|
||||||
let user = String::from_utf8_lossy(&user.stdout);
|
// let user = String::from_utf8_lossy(&user.stdout);
|
||||||
|
|
||||||
let hostname = Command::new("uname")
|
// let hostname = Command::new("uname")
|
||||||
.args(["-n"])
|
// .args(["-n"])
|
||||||
.output()
|
// .output()
|
||||||
.expect("Failed to get hostname");
|
// .expect("Failed to get hostname");
|
||||||
|
|
||||||
let hostname = String::from_utf8_lossy(&hostname.stdout);
|
|
||||||
|
|
||||||
// Don't print user and hostname just yet.
|
|
||||||
|
|
||||||
// println!("{}@{}", user.trim(), hostname.trim());
|
// let hostname = String::from_utf8_lossy(&hostname.stdout);
|
||||||
// println!("══════════════════════════════════");
|
let user = env::var("USER");
|
||||||
|
|
||||||
// drop(user);
|
|
||||||
//drop(hostname);
|
|
||||||
|
|
||||||
|
let mut hostname = String::new();
|
||||||
|
{
|
||||||
|
let hostname_file = File::open("/etc/hostname").expect("u forgor the /etc/hostname file u arch-using moronbox");
|
||||||
|
let mut hostname_reader = BufReader::new(hostname_file);
|
||||||
|
hostname_reader.read_line(&mut hostname).expect("Failed string conversion... EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE");
|
||||||
|
}
|
||||||
|
|
||||||
// Read release file, AKA get OS name
|
// Read release file, AKA get OS name
|
||||||
let mut release_distro = String::new();
|
let mut release_distro = String::new();
|
||||||
|
@ -38,36 +39,38 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release file processing, huge credit to ChatGPT for this one!
|
// Release file processing, huge credit to ChatGPT for this one!
|
||||||
let mut distro_name: String = release_distro[5..release_distro.len() - 1].to_string();
|
let mut distro_name: String = release_distro[5..release_distro.len() - 1].to_string();
|
||||||
distro_name = distro_name.replace('\"', "");
|
distro_name = distro_name.replace('\"', "");
|
||||||
// println!("OS: {}", Red.paint(distro_name.clone()));
|
// println!("OS: {}", Red.paint(distro_name.clone()));
|
||||||
|
|
||||||
let figlet = Command::new("figlet")
|
let figlet = Command::new("figlet")
|
||||||
.args(["-f", "smslant", &distro_name])
|
.args(["-f", "smslant", &distro_name])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
if let Ok(output) = figlet {
|
if let Ok(output) = figlet {
|
||||||
let output = String::from_utf8_lossy(&output.stdout);
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
print!("{}", output);
|
print!("{}", output);
|
||||||
}
|
}
|
||||||
// Print all the things we've been saving.
|
// Print all the things we've been saving.
|
||||||
println!("{}@{}", user.clone().trim(), hostname.clone().trim());
|
println!("{}@{}", user.unwrap(), hostname);
|
||||||
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||||
println!("┐ OS: {}", Red.paint(distro_name.clone()));
|
println!("┐ OS: {}", Red.paint(distro_name));
|
||||||
|
|
||||||
// Free up RAM
|
// I know it's terrible, but it works.
|
||||||
drop(release_distro);
|
let mut kernel = String::new();
|
||||||
drop(distro_name);
|
{
|
||||||
|
let kernel_file = File::open("/proc/version").expect("do u even linux bro???");
|
||||||
|
let mut kernel_reader = BufReader::new(kernel_file);
|
||||||
|
kernel_reader.read_line(&mut kernel).expect("Failed string conversion");
|
||||||
|
}
|
||||||
|
|
||||||
// Kernel Version
|
let mut kernel_name: String = (kernel[14..kernel.len()]).to_string();
|
||||||
let kernel = Command::new("uname")
|
kernel_name = kernel_name.split_whitespace()
|
||||||
.arg("-r")
|
.next()
|
||||||
.output()
|
.unwrap()
|
||||||
.expect("Couldn't get kernel version!");
|
.to_string();
|
||||||
|
|
||||||
let kernel = String::from_utf8_lossy(&kernel.stdout);
|
println!("│ Kernel: {}", Yellow.paint(kernel_name.trim()));
|
||||||
|
|
||||||
println!("│ Kernel: {}", Yellow.paint(kernel.trim()));
|
|
||||||
|
|
||||||
// Read memfile
|
// Read memfile
|
||||||
if let Ok(file) = File::open("/proc/meminfo") {
|
if let Ok(file) = File::open("/proc/meminfo") {
|
||||||
|
@ -110,18 +113,25 @@ fn main() {
|
||||||
|
|
||||||
println!("│ Mem: {}/{} GB ({} GB Available)", Green.paint(ramused.to_string()), Green.paint(ramtotal.to_string()), Green.paint(ramavail.to_string()));
|
println!("│ Mem: {}/{} GB ({} GB Available)", Green.paint(ramused.to_string()), Green.paint(ramtotal.to_string()), Green.paint(ramavail.to_string()));
|
||||||
|
|
||||||
// Read Uptime
|
}
|
||||||
|
|
||||||
let uptime = Command::new("uptime")
|
{
|
||||||
.output()
|
// This took me unusually long.
|
||||||
.expect("Failed to get uptime");
|
|
||||||
|
// Generic file stuff
|
||||||
|
let mut uptime = String::new();
|
||||||
|
let uptime_file = File::open("/proc/uptime").expect(":skull:");
|
||||||
|
let mut uptime_reader = BufReader::new(uptime_file);
|
||||||
|
uptime_reader.read_line(&mut uptime).expect("what");
|
||||||
|
let mut iterator = uptime.split_whitespace();
|
||||||
|
uptime = iterator.next().expect("*screeches at the top of his lungs*").to_string();
|
||||||
|
|
||||||
|
// was never expecting rounding to be this difficult
|
||||||
|
let uptimeint = uptime.parse::<f32>();
|
||||||
|
let roundeduptimeint: u32 = uptimeint.expect("phoque").round() as u32;
|
||||||
|
let uptimemins: u32 = roundeduptimeint / 60;
|
||||||
|
println!("│ Uptime: {} minutes", Blue.paint(uptimemins.to_string()))
|
||||||
|
|
||||||
let mut uptime = String::from_utf8_lossy(&uptime.stdout).trim().to_string();
|
|
||||||
uptime = uptime.split_whitespace().nth(2).unwrap_or("").to_string();
|
|
||||||
uptime = uptime[0..uptime.len() - 1].to_string();
|
|
||||||
println!("│ Uptime: {} (H:MM)", Blue.paint(uptime));
|
|
||||||
} else {
|
|
||||||
panic!("Cannot find /proc/meminfo");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get shell
|
// Get shell
|
||||||
|
@ -141,17 +151,17 @@ fn main() {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut model: String = String::new();
|
let mut model: String = String::new();
|
||||||
|
|
||||||
if let Some(Ok(line)) = lines.next() {
|
if let Some(Ok(line)) = lines.next() {
|
||||||
model = line.split(':').nth(1).expect("Failed to parse CPU Info").trim().to_string();
|
model = line.split(':').nth(1).expect("Failed to parse CPU Info").trim().to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("┘ CPU: {}", Purple.paint(model));
|
println!("┘ CPU: {}", Purple.paint(model));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Colours
|
// Colours
|
||||||
println!("\n{} {} {} {} {} {}", Red.paint("◆"), Green.paint("◆"), Yellow.paint("◆"), Blue.paint("◆"), Purple.paint("◆"), Cyan.paint("◆"));
|
println!("\n{} {} {} {} {} {}", Red.paint("◆"), Green.paint("◆"), Yellow.paint("◆"), Blue.paint("◆"), Purple.paint("◆"), Cyan.paint("◆"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue