-
Notifications
You must be signed in to change notification settings - Fork 8
/
fetch.rs
executable file
·52 lines (43 loc) · 2.59 KB
/
fetch.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//bin/true; rustc -o "/tmp/$0.bin" 1>&2 "$0" && "/tmp/$0.bin" "$@"; exit 0;
use std::fs::File;
use std::io::prelude::*;
fn main() {
let shell = std::env::var("SHELL").unwrap();
// Please simplify this code, im fucking bad at rust
// but atleast the uptime is correct now :p
let mut upfile = File::open("/proc/uptime").unwrap(); // Read uptime from /proc/uptime (idk if this is in all distros but i guess so
let mut uptime = String::new();
upfile.read_to_string(&mut uptime).unwrap(); // Put uptime file text into uptime variable
let v: Vec<&str> = uptime.split(" ").collect(); // Split uptime, because it has more than just the seconds
let upsecs = v[0].parse::<f32>().unwrap(); // Parse floating number from index 0, cuz we need that to "beautify" it
let secs = upsecs % 60.0; // calculate the seconds
let upsecs = upsecs as i64; // convert to integer to avoid unnecessary rounding of float value
let mins = (upsecs / 60) % 60; // calculate the minutes
let hours = (upsecs / 3600) % 24; // calculate the hours
let days = upsecs / (3600 * 24); // calculate the days
let uptime = format!("{days:.0} days, {hours:.0}h {mins:.0}m {secs:.1}s"); // mak it butiful
let mut file = File::open("/etc/hostname").unwrap();
let mut hostname = String::new();
file.read_to_string(&mut hostname).unwrap(); //.strip()
let hostname = hostname.replace("\n", "");
let mut file = File::open("/etc/issue").unwrap();
let mut distro = String::new();
file.read_to_string(&mut distro).unwrap(); //.strip()
let distro = distro.replacen("(\\l)", "", 3).replace("\r", "").replace("\n", "");
let mut file = File::open("/proc/sys/kernel/ostype").unwrap(); // Read OS Type (should be "Linux")
let mut ostype = String::new();
file.read_to_string(&mut ostype).unwrap();
let mut file = File::open("/proc/sys/kernel/osrelease").unwrap(); // Read OS Release (should be the kernel version)
let mut osrelease = String::new();
file.read_to_string(&mut osrelease).unwrap();
let kernel = format!("{} {}", ostype.replace("\n", ""), osrelease.replace("\n", ""));
// probably a bit more involved
// # terminal = os.ctermid()
println!();
println!("(\\_/) \x1b[0;33m uptime: {uptime}\x1b[0;0m"); //orange
println!("(oᴥo) \x1b[0;31m shell: {shell}\x1b[0;0m"); //red
println!("|U°U| \x1b[0;35m distro: {distro}\x1b[0;0m"); //purple
println!("| | \x1b[0;34m hostname: {hostname}\x1b[0;0m"); //blue
println!("'U_U' \x1b[0;36m kernel: {kernel}\x1b[0;0m"); //cyan
println!(" U" );
}