This commit is contained in:
nicknase27 committed 2026-10-07 18:34:31 +02:00
commit ab4ef70657
5 files changed
+157

No files matched your search

+1
View File
@@ -0,0 +1 @@
/target
Generated
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "rfetch"
version = "0.1.0"
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "rfetch"
version = "0.1.0"
edition = "2024"
license = "MIT"
[dependencies]
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 nicknase27.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+121
View File
@@ -0,0 +1,121 @@
use std::env;
use std::fs::read_to_string;
fn print_logo() {
print!(
r"
---
(.· |
(<> |
/ __ \
( / \\ /|
_/\ __)/_)
\/-____\/
"
);
}
#[cfg(target_os = "linux")]
fn get_os() -> String {
let contents: Vec<String> = read_to_string("/etc/os-release")
.unwrap()
.lines()
.map(String::from)
.collect();
let os = contents[0]
.trim_start_matches("NAME=")
.trim_matches('"')
.to_string();
return os;
}
#[cfg(unix)]
fn get_shell() -> String {
match env::var("SHELL") {
Ok(shell) => shell.split('/').last().unwrap_or(&shell).to_string(),
Err(e) => e.to_string(),
}
}
#[cfg(unix)]
fn get_host() -> String {
read_to_string("/etc/hostname").unwrap().trim().to_string()
}
#[cfg(target_os = "linux")]
fn get_kernel() -> String {
let kernel = read_to_string("/proc/sys/kernel/osrelease")
.unwrap()
.trim()
.to_string();
format!("Linux {}", kernel)
}
#[cfg(not(target_os = "linux"))]
fn get_kernel() -> String {
String::new()
}
fn get_terminal() -> String {
match env::var("TERM") {
Ok(term) => term,
Err(e) => e.to_string(),
}
}
#[cfg(target_os = "linux")]
fn get_memory() -> String {
let content = read_to_string("/proc/meminfo").unwrap_or_default();
let mut mem_total: u64 = 0;
let mut mem_avail: u64 = 0;
for line in content.lines() {
if line.starts_with("MemTotal:") {
mem_total = line
.split_whitespace()
.nth(1)
.unwrap_or("0")
.parse()
.unwrap_or(0);
} else if line.starts_with("MemAvailable:") {
mem_avail = line
.split_whitespace()
.nth(1)
.unwrap_or("0")
.parse()
.unwrap_or(0);
}
}
let mem_used = mem_total.saturating_sub(mem_avail);
let used_gib = mem_used as f64 / 1048576.0;
let total_gib = mem_total as f64 / 1048576.0;
if used_gib > 1.0 {
format!("{:.2} GiB / {:.2} GiB", used_gib, total_gib)
} else {
let used_mib = mem_used as f64 / 1024.0;
format!("{:.1} MiB / {:.2} GiB", used_mib, total_gib)
}
}
#[cfg(not(target_os = "linux"))]
fn get_memory() -> String {
String::new()
}
fn main() {
let os = get_os();
let shell = get_shell();
let kernel = get_kernel();
let host = get_host();
let term = get_terminal();
let memory = get_memory();
print_logo();
println!(
"\nOS: {}\nShell: {}\nKernel: {}\nHost: {}\nTerm: {}\nMemory: {}",
os, shell, kernel, host, term, memory
);
}