2024-03-31 18:49:58 +01:00
|
|
|
use clap::Parser;
|
2024-05-05 23:45:36 +01:00
|
|
|
use owo_colors::{AnsiColors::*, OwoColorize};
|
2024-03-24 21:05:25 +00:00
|
|
|
use std::{env::var, path::PathBuf};
|
2024-03-23 22:35:06 +00:00
|
|
|
use sysinfo::System;
|
|
|
|
use whoami::*;
|
2024-03-24 12:48:11 +00:00
|
|
|
|
|
|
|
/// A simple and adorable sysinfo utility written in Rust.
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
#[command(version, about, long_about = None)]
|
|
|
|
struct Args {
|
|
|
|
/// Show ASCII art only
|
|
|
|
#[arg(short, long)]
|
|
|
|
ascii_only: bool,
|
|
|
|
|
|
|
|
/// Show CPU architecture
|
|
|
|
#[arg(short = 'x', long)]
|
|
|
|
arch: bool,
|
2024-03-24 13:04:37 +00:00
|
|
|
|
2024-03-24 21:05:25 +00:00
|
|
|
/// Show the kernel version
|
|
|
|
#[arg(short = 'k', long)]
|
|
|
|
kernel: bool,
|
|
|
|
|
2024-10-29 18:35:54 +00:00
|
|
|
/// Hide the username and hostname
|
|
|
|
#[arg(short = 'u', long)]
|
|
|
|
hide_combined: bool,
|
|
|
|
|
2024-03-31 18:49:58 +01:00
|
|
|
/// Hide terminal colours
|
2024-03-24 13:04:37 +00:00
|
|
|
#[arg(short = 'z', long, default_value_t = false)]
|
|
|
|
hide_colours: bool,
|
2024-10-29 19:40:46 +00:00
|
|
|
|
|
|
|
/// Use the alternative ASCII art
|
|
|
|
#[arg(short = 'A', long, default_value_t = false)]
|
|
|
|
alt_art: bool,
|
2024-03-24 12:48:11 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 21:05:25 +00:00
|
|
|
// Display the CPU architecture
|
2024-03-24 13:04:37 +00:00
|
|
|
fn cpu_arch(args: &Args) {
|
2024-03-24 12:48:11 +00:00
|
|
|
if args.arch {
|
|
|
|
let arch = arch();
|
|
|
|
println!("{:>17} {}", "Arch".cyan().bold(), arch);
|
|
|
|
}
|
|
|
|
}
|
2024-03-23 21:58:32 +00:00
|
|
|
|
2024-03-24 21:05:25 +00:00
|
|
|
// Display the kernel version
|
|
|
|
fn display_kernel(args: &Args) {
|
|
|
|
if args.kernel {
|
|
|
|
let kernel = System::kernel_version().unwrap_or(String::from("N/A"));
|
|
|
|
println!("{:>19} {}", "Kernel".yellow().bold(), kernel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-29 18:35:54 +00:00
|
|
|
// Hide the username@hostname text
|
|
|
|
fn hide_combined(args: &Args) {
|
|
|
|
if !args.hide_combined {
|
|
|
|
let hostname = fallible::hostname().unwrap_or(String::from("N/A"));
|
|
|
|
let user = username();
|
|
|
|
let combined = format!("{}@{}", user, hostname);
|
|
|
|
println!("{: <13}{}", "", combined.bold());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-29 19:40:46 +00:00
|
|
|
// Display the ASCII art
|
|
|
|
fn ascii_art(args: &Args) -> [String; 3] {
|
|
|
|
if !args.alt_art {
|
|
|
|
let bottom = format!("c({})({})", "\"".red(), "\"".red()).to_string();
|
|
|
|
return ["(\\ /)".to_string(), "( . .)".to_string(), bottom];
|
|
|
|
} else {
|
|
|
|
let top = format!("{}", ".".red()).to_string();
|
|
|
|
return [top, "\\\\ /\\".to_string(), " \\\\//v".to_string()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-23 21:58:32 +00:00
|
|
|
fn main() {
|
2024-03-24 12:48:11 +00:00
|
|
|
let args = Args::parse();
|
|
|
|
|
2024-03-23 22:35:06 +00:00
|
|
|
let pretty = distro();
|
2024-03-24 14:13:36 +00:00
|
|
|
|
|
|
|
let wm: String;
|
2024-03-23 22:35:06 +00:00
|
|
|
|
|
|
|
if cfg!(windows) {
|
2024-05-05 22:20:47 +01:00
|
|
|
wm = "Aero".to_string();
|
2024-03-23 22:35:06 +00:00
|
|
|
} else if cfg!(unix) {
|
2024-03-24 20:28:20 +00:00
|
|
|
let xdg_current_desktop = var("XDG_CURRENT_DESKTOP");
|
|
|
|
let desktop = desktop_env().to_string();
|
2024-03-24 20:40:30 +00:00
|
|
|
if desktop != "Unknown: Unknown" {
|
2024-03-24 20:28:20 +00:00
|
|
|
wm = desktop;
|
2024-03-31 18:51:28 +01:00
|
|
|
} else if xdg_current_desktop.is_ok() {
|
2024-03-24 20:28:20 +00:00
|
|
|
wm = xdg_current_desktop.unwrap();
|
2024-03-24 20:40:30 +00:00
|
|
|
} else {
|
|
|
|
wm = "N/A".to_string();
|
2024-03-24 20:28:20 +00:00
|
|
|
}
|
2024-03-24 14:08:46 +00:00
|
|
|
} else {
|
2024-03-24 14:13:36 +00:00
|
|
|
wm = "N/A".to_string();
|
2024-03-23 21:58:32 +00:00
|
|
|
}
|
2024-03-23 22:35:06 +00:00
|
|
|
|
2024-03-24 21:05:25 +00:00
|
|
|
let shell_path = PathBuf::from(var("SHELL").unwrap_or(String::from("N/A")));
|
2024-03-31 18:49:58 +01:00
|
|
|
let shell = shell_path
|
|
|
|
.file_name()
|
|
|
|
.expect("Could not get $SHELL path")
|
|
|
|
.to_str()
|
|
|
|
.unwrap();
|
2024-03-24 21:05:25 +00:00
|
|
|
|
2024-03-24 12:48:11 +00:00
|
|
|
println!();
|
|
|
|
if !args.ascii_only {
|
2024-10-29 18:35:54 +00:00
|
|
|
hide_combined(&args);
|
2024-03-24 13:04:37 +00:00
|
|
|
cpu_arch(&args);
|
2024-03-24 21:05:25 +00:00
|
|
|
display_kernel(&args);
|
2024-10-29 19:40:46 +00:00
|
|
|
let ascii = ascii_art(&args);
|
|
|
|
|
|
|
|
let spacings: [usize; 3];
|
|
|
|
if args.alt_art {
|
|
|
|
spacings = [
|
|
|
|
(7 - (ascii[0].len() - 10))+2,
|
|
|
|
(7 - ascii[1].len())+2,
|
|
|
|
(7 - ascii[2].len())+2,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
spacings = [
|
|
|
|
(7 - ascii[0].len())+2,
|
|
|
|
(7 - ascii[1].len())+2,
|
|
|
|
(7 - (ascii[2].len() - 20))+2,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
println!(" {}{} {} {}", ascii[0], " ".to_string().repeat(spacings[0]), "OS".red().bold(), pretty);
|
|
|
|
println!(" {}{} {} {}", ascii[1], " ".to_string().repeat(spacings[1]), "Shell".green().bold(), shell);
|
|
|
|
println!(" {}{} {} {}", ascii[2], " ".to_string().repeat(spacings[2]), "WM".blue().bold(), wm);
|
2024-03-24 12:48:11 +00:00
|
|
|
} else {
|
2024-10-29 19:40:46 +00:00
|
|
|
for i in ascii_art(&args) {
|
2024-03-24 12:48:11 +00:00
|
|
|
println!(" {}", i);
|
|
|
|
}
|
|
|
|
}
|
2024-03-24 13:04:37 +00:00
|
|
|
|
2024-03-24 13:50:31 +00:00
|
|
|
if !args.hide_colours && !args.ascii_only {
|
2024-03-24 13:04:37 +00:00
|
|
|
println!();
|
2024-05-05 23:45:36 +01:00
|
|
|
let colors = [Black, Red, Green, Yellow, Blue, Magenta, Cyan, White];
|
|
|
|
let mut color_string: String = " ".to_string();
|
2024-03-24 13:04:37 +00:00
|
|
|
for color in colors {
|
|
|
|
color_string.push_str(&format!("{:>3}", "●".color(color)));
|
|
|
|
}
|
|
|
|
println!("{}", color_string);
|
|
|
|
}
|
2024-03-23 21:58:32 +00:00
|
|
|
}
|