Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
mod cpu;
#[path = "modules/de.rs"]
mod de;
#[path = "modules/disk.rs"]
mod disk;
#[path = "modules/gpu.rs"]
mod gpu;
#[path = "modules/host.rs"]
mod host;
#[path = "modules/kernel.rs"]
mod kernel;
#[path = "modules/machine.rs"]
mod machine;
#[path = "modules/mem.rs"]
mod mem;
#[path = "modules/os.rs"]
Expand All @@ -20,12 +26,6 @@ mod sh;
mod up;
#[path = "modules/user.rs"]
mod user;
#[path = "modules/disk.rs"]
mod disk;
#[path = "modules/gpu.rs"]
mod gpu;
#[path = "modules/machine.rs"]
mod machine;

pub fn info() {
match (user::get_user(), host::get_host()) {
Expand All @@ -43,7 +43,7 @@ pub fn info() {
if let Ok(kernel) = kernel::get_kernel() {
println!("Kernel : {}", kernel);
}

if let Ok(machine) = machine::get_machine() {
println!("Host : {}", machine);
}
Expand Down
14 changes: 6 additions & 8 deletions src/modules/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ pub fn get_cpu() -> io::Result<String> {
let file = File::open("/proc/cpuinfo")?; // /proc/cpuinfo contains the cpu informations

// Read the file line by line
for line in io::BufReader::new(file).lines() {
if let Ok(line) = line {
// Check for the "model name" line
if line.starts_with("model name") {
// Extract the model name
let model_name = line.split(':').nth(1).map(|s| s.trim());
return Ok(model_name.unwrap_or("N/A").to_string());
}
for line in io::BufReader::new(file).lines().flatten() {
// Check for the "model name" line
if line.starts_with("model name") {
// Extract the model name
let model_name = line.split(':').nth(1).map(|s| s.trim());
return Ok(model_name.unwrap_or("N/A").to_string());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/disk.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::process::{Command, exit};
use std::io;
use std::process::{exit, Command};

pub fn get_disk() -> io::Result<String> {
// Run the df command and capture its output
Expand Down
6 changes: 4 additions & 2 deletions src/modules/gpu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::process::{Command, exit};
use std::io;
use std::process::{exit, Command};

pub fn get_gpu() -> io::Result<String> {
// Run the lspci command and capture its output
Expand All @@ -12,7 +12,9 @@ pub fn get_gpu() -> io::Result<String> {
let output_str = String::from_utf8_lossy(&output.stdout);

// Search for GPU-related information in the lspci output
if let Some(line) = output_str.lines().find(|line| line.to_lowercase().contains("vga") || line.to_lowercase().contains("3d")) {
if let Some(line) = output_str.lines().find(|line| {
line.to_lowercase().contains("vga") || line.to_lowercase().contains("3d")
}) {
// Extract the GPU model information
let gpu_model = line.split(':').nth(2).map(|s| s.trim());

Expand Down
2 changes: 1 addition & 1 deletion src/modules/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn get_kernel() -> io::Result<String> {
if output.status.success() {
// Convert the output to a string
let kernel_version = String::from_utf8_lossy(&output.stdout).trim().to_string();
return Ok(kernel_version);
Ok(kernel_version)
} else {
// Print the error code and exit the program
eprintln!("Command failed with error code: {}", output.status);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub fn get_machine() -> io::Result<String> {
let name = read_to_string(Path::new("/sys/devices/virtual/dmi/id/product_name"))?;
let version = read_to_string(Path::new("/sys/devices/virtual/dmi/id/product_version"))?;

Ok(format!("{} {}", name.trim().to_string(), version.trim().to_string()))
Ok(format!("{} {}", name.trim(), version.trim()))
}
14 changes: 6 additions & 8 deletions src/modules/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ pub fn get_mem() -> io::Result<String> {
let mut mem_free: u64 = 0;

// Read the file line by line
for line in io::BufReader::new(file).lines() {
if let Ok(line) = line {
// Extract MemTotal and MemFree values
if line.starts_with("MemTotal:") {
mem_total = parse_memory_value(&line);
} else if line.starts_with("MemFree:") {
mem_free = parse_memory_value(&line);
}
for line in io::BufReader::new(file).lines().flatten() {
// Extract MemTotal and MemFree values
if line.starts_with("MemTotal:") {
mem_total = parse_memory_value(&line);
} else if line.starts_with("MemFree:") {
mem_free = parse_memory_value(&line);
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/modules/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ pub fn get_os() -> io::Result<String> {
let file = File::open("/etc/os-release")?;

// Read the file line by line
for line in io::BufReader::new(file).lines() {
if let Ok(line) = line {
// Check for the "PRETTY_NAME" field
if line.starts_with("PRETTY_NAME=") {
// Extract the value of PRETTY_NAME
let pretty_name = line.split('=').nth(1).map(|s| s.trim_matches('"'));
return Ok(pretty_name.unwrap_or("N/A").to_string());
}
for line in io::BufReader::new(file).lines().flatten() {
// Check for the "PRETTY_NAME" field
if line.starts_with("PRETTY_NAME=") {
// Extract the value of PRETTY_NAME
let pretty_name = line.split('=').nth(1).map(|s| s.trim_matches('"'));
return Ok(pretty_name.unwrap_or("N/A").to_string());
}
}

Expand Down
66 changes: 51 additions & 15 deletions src/modules/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,101 @@ pub fn get_pkg() -> io::Result<String> {
if Path::new("/bin/dpkg").exists() {
let output = Command::new("sh")
.arg("-c")
.arg(format!("dpkg --get-selections | wc -l"))
.arg("dpkg --get-selections | wc -l")
.output()?;

if String::from_utf8_lossy(&output.stdout).trim().parse::<i32>().unwrap() != 0 {

if String::from_utf8_lossy(&output.stdout)
.trim()
.parse::<i32>()
.unwrap()
!= 0
{
result += &format!("{} (dpkg) ", String::from_utf8_lossy(&output.stdout).trim());
}
}

if Path::new("/bin/flatpak").exists() {
let output = Command::new("sh")
.arg("-c")
.arg(format!("flatpak list | wc -l"))
.arg("flatpak list | wc -l")
.output()?;

if String::from_utf8_lossy(&output.stdout).trim().parse::<i32>().unwrap() != 0 {
result += &format!("{} (flatpak) ", String::from_utf8_lossy(&output.stdout).trim());
if String::from_utf8_lossy(&output.stdout)
.trim()
.parse::<i32>()
.unwrap()
!= 0
{
result += &format!(
"{} (flatpak) ",
String::from_utf8_lossy(&output.stdout).trim()
);
}
}

if Path::new("/bin/pacman").exists() {
let output = Command::new("sh")
.arg("-c")
.arg(format!("pacman -Qq | wc -l"))
.arg("pacman -Qq | wc -l")
.output()?;

if String::from_utf8_lossy(&output.stdout).trim().parse::<i32>().unwrap() != 0 {
result += &format!("{} (pacman) ", String::from_utf8_lossy(&output.stdout).trim());
if String::from_utf8_lossy(&output.stdout)
.trim()
.parse::<i32>()
.unwrap()
!= 0
{
result += &format!(
"{} (pacman) ",
String::from_utf8_lossy(&output.stdout).trim()
);
}
}

if Path::new("/var/lib/rpm").exists() {
let output = Command::new("sh")
.arg("-c")
.arg(format!("rpm -qa | wc -l"))
.arg("rpm -qa | wc -l")
.output()?;

if String::from_utf8_lossy(&output.stdout).trim().parse::<i32>().unwrap() != 0 {
if String::from_utf8_lossy(&output.stdout)
.trim()
.parse::<i32>()
.unwrap()
!= 0
{
result += &format!("{} (rpm) ", String::from_utf8_lossy(&output.stdout).trim());
}
}

if Path::new("/bin/snap").exists() {
let output = Command::new("sh")
.arg("-c")
.arg(format!("snap list | wc -l"))
.arg("snap list | wc -l")
.output()?;

if String::from_utf8_lossy(&output.stdout).trim().parse::<i32>().unwrap() != 0 {
if String::from_utf8_lossy(&output.stdout)
.trim()
.parse::<i32>()
.unwrap()
!= 0
{
result += &format!("{} (snap) ", String::from_utf8_lossy(&output.stdout).trim());
}
}

if Path::new("/bin/xbps-install").exists() {
let output = Command::new("sh")
.arg("-c")
.arg(format!("xbps-query -l | wc -l"))
.arg("xbps-query -l | wc -l")
.output()?;

if String::from_utf8_lossy(&output.stdout).trim().parse::<i32>().unwrap() != 0 {
if String::from_utf8_lossy(&output.stdout)
.trim()
.parse::<i32>()
.unwrap()
!= 0
{
result += &format!("{} (xbps) ", String::from_utf8_lossy(&output.stdout).trim());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/res.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::process::{Command, exit};
use std::io;
use std::process::{exit, Command};

pub fn get_res() -> io::Result<String> {
// Run the xrandr command and capture its output
Expand Down
4 changes: 2 additions & 2 deletions src/modules/uptime.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::process::{Command, exit};
use std::io;
use std::process::{exit, Command};

pub fn get_uptime() -> io::Result<String> {
// Run the uptime -p command and capture its output
Expand Down Expand Up @@ -27,4 +27,4 @@ pub fn get_uptime() -> io::Result<String> {
exit(1);
}
}
}
}