mirror of
https://github.com/NotAShelf/microfetch.git
synced 2024-11-22 15:40:41 +00:00
Compare commits
6 commits
fc62d72cab
...
2ecf9303fa
Author | SHA1 | Date | |
---|---|---|---|
2ecf9303fa | |||
7d693ea26f | |||
72d3130aa0 | |||
482ffe96cd | |||
cf0a52150c | |||
e3112dba1d |
6 changed files with 50 additions and 31 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -105,7 +105,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "microfetch"
|
name = "microfetch"
|
||||||
version = "0.3.0"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"nix",
|
"nix",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "microfetch"
|
name = "microfetch"
|
||||||
version = "0.3.0"
|
version = "0.3.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
36
README.md
36
README.md
|
@ -12,7 +12,7 @@ welcome to use it on your system: it's fast.
|
||||||
- Fast
|
- Fast
|
||||||
- Really fast
|
- Really fast
|
||||||
- Minimal dependencies
|
- Minimal dependencies
|
||||||
- Actually very fast
|
- Actually really fast
|
||||||
- Cool NixOS logo (other, inferior, distros are not supported)
|
- Cool NixOS logo (other, inferior, distros are not supported)
|
||||||
- Reliable detection of following info:
|
- Reliable detection of following info:
|
||||||
- Hostname/Username
|
- Hostname/Username
|
||||||
|
@ -25,11 +25,45 @@ welcome to use it on your system: it's fast.
|
||||||
- Memory Usage/Total Memory
|
- Memory Usage/Total Memory
|
||||||
- Storage Usage/Total Storage (for `/` only)
|
- Storage Usage/Total Storage (for `/` only)
|
||||||
- Shell Colors
|
- Shell Colors
|
||||||
|
- Did I mention fast?
|
||||||
|
|
||||||
|
## Benchmarks
|
||||||
|
|
||||||
|
Microfetch's performance is mostly hardware-dependant, however, the overall
|
||||||
|
trend seems to be < 2ms on any modern (2015 and after) CPU. Below are the
|
||||||
|
benchmarks with Hyperfine on my desktop system.
|
||||||
|
|
||||||
|
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||||
|
| :-------------------------- | --------: | -------: | -------: | -------: |
|
||||||
|
| `target/release/microfetch` | 1.3 ± 0.1 | 1.2 | 3.7 | 1.00 |
|
||||||
|
|
||||||
|
On an average configuration, this is roughly 25 times faster than fastfetch and
|
||||||
|
around 80 times faster than neofetch. Results, as stated above, may vary.
|
||||||
|
|
||||||
## Customizing
|
## Customizing
|
||||||
|
|
||||||
You can't.
|
You can't.
|
||||||
|
|
||||||
|
### Why?
|
||||||
|
|
||||||
|
Customization, of any kind, is expensive: I could try reading environment
|
||||||
|
variables, parse command-line arguments or read a configuration file but all of
|
||||||
|
those increment execution time and resource consumption by a lot.
|
||||||
|
|
||||||
|
### Really?
|
||||||
|
|
||||||
|
To be fair, you _can_ customize Microfetch by... Well, patching it. It's not the
|
||||||
|
best way per se, but it will be the only way that does not compromise on speed.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
I will, mostly, reject feature additions. This is not to say you should avoid
|
||||||
|
them altogether, as you might have a really good idea worth discussing but as a
|
||||||
|
general rule of thumb consider talking to me before creating a feature PR.
|
||||||
|
|
||||||
|
Contributions that help improve performance in specific areas of Microfetch are
|
||||||
|
welcome. Though, prepare to be bombarded with questions.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Microfetch is licensed under [GPL3](LICENSE). See the license file for details.
|
Microfetch is licensed under [GPL3](LICENSE). See the license file for details.
|
||||||
|
|
|
@ -1,26 +1,19 @@
|
||||||
use std::{env, io};
|
use std::{env, io};
|
||||||
|
|
||||||
pub fn get_desktop_info() -> Result<String, io::Error> {
|
pub fn get_desktop_info() -> Result<String, io::Error> {
|
||||||
let desktop_env = env::var("XDG_CURRENT_DESKTOP").unwrap_or_default();
|
let desktop_env = env::var("XDG_CURRENT_DESKTOP");
|
||||||
let display_backend = env::var("XDG_SESSION_TYPE").unwrap_or_default();
|
let display_backend = env::var("XDG_SESSION_TYPE");
|
||||||
|
|
||||||
// Trim "none+" from the start of desktop_env if present
|
// Trim "none+" from the start of desktop_env if present
|
||||||
// XXX: This is a workaround for NixOS modules that set XDG_CURRENT_DESKTOP to "none+foo"
|
// XXX: This is a workaround for NixOS modules that set XDG_CURRENT_DESKTOP to "none+foo"
|
||||||
// instead of just "foo"
|
// instead of just "foo"
|
||||||
let desktop_env = desktop_env.trim_start_matches("none+");
|
|
||||||
|
|
||||||
// Use "Unknown" if desktop_env or display_backend is empty
|
// Use "Unknown" if desktop_env or display_backend is empty
|
||||||
let desktop_env = if desktop_env.is_empty() {
|
let desktop_env = match desktop_env {
|
||||||
"Unknown"
|
Err(_) => String::from("Unknown"),
|
||||||
} else {
|
Ok(s) => s.trim_start_matches("none+").to_owned(),
|
||||||
desktop_env
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let display_backend = if display_backend.is_empty() {
|
let display_backend = display_backend.unwrap_or_else(|_| String::from("Unknown"));
|
||||||
"Unknown"
|
|
||||||
} else {
|
|
||||||
&display_backend
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(format!("{desktop_env} ({display_backend})"))
|
Ok(format!("{desktop_env} ({display_backend})"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,10 @@ pub fn get_username_and_hostname() -> Result<String, io::Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_shell() -> Result<String, io::Error> {
|
pub fn get_shell() -> Result<String, io::Error> {
|
||||||
// In some setups, $SHELL is set to the store path
|
let shell_path = env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_string());
|
||||||
// of the actual shell program. While we can consider
|
let shell_name = shell_path.rsplit('/').next().unwrap_or("unknown_shell");
|
||||||
// trimming by name, I will leave it to the user to handle
|
|
||||||
// what their SHELL variable is really set to.
|
|
||||||
let shell = env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_string());
|
|
||||||
|
|
||||||
Ok(shell)
|
Ok(shell_name.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_root_disk_usage() -> Result<String, io::Error> {
|
pub fn get_root_disk_usage() -> Result<String, io::Error> {
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead, BufReader};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn get_current() -> Result<String, io::Error> {
|
pub fn get_current() -> Result<String, io::Error> {
|
||||||
let path = Path::new("/proc/uptime");
|
let path = Path::new("/proc/uptime");
|
||||||
let file = File::open(path)?;
|
let file = File::open(path)?;
|
||||||
let reader = io::BufReader::new(file);
|
let mut reader = BufReader::new(file);
|
||||||
|
|
||||||
let line = reader
|
let mut line = String::new();
|
||||||
.lines()
|
reader.read_line(&mut line)?;
|
||||||
.next()
|
|
||||||
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Failed to read uptime"))??;
|
|
||||||
|
|
||||||
let uptime_seconds: f64 = line
|
let uptime_seconds: f64 = line
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
|
@ -19,7 +17,6 @@ pub fn get_current() -> Result<String, io::Error> {
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
||||||
|
|
||||||
// calculate days, hours, and minutes
|
|
||||||
let total_minutes = (uptime_seconds / 60.0).round() as u64;
|
let total_minutes = (uptime_seconds / 60.0).round() as u64;
|
||||||
let days = total_minutes / (60 * 24);
|
let days = total_minutes / (60 * 24);
|
||||||
let hours = (total_minutes % (60 * 24)) / 60;
|
let hours = (total_minutes % (60 * 24)) / 60;
|
||||||
|
@ -29,11 +26,9 @@ pub fn get_current() -> Result<String, io::Error> {
|
||||||
if days > 0 {
|
if days > 0 {
|
||||||
parts.push(format!("{days} days"));
|
parts.push(format!("{days} days"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if hours > 0 || days > 0 {
|
if hours > 0 || days > 0 {
|
||||||
parts.push(format!("{hours} hours"));
|
parts.push(format!("{hours} hours"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if minutes > 0 || hours > 0 || days > 0 {
|
if minutes > 0 || hours > 0 || days > 0 {
|
||||||
parts.push(format!("{minutes} minutes"));
|
parts.push(format!("{minutes} minutes"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue