diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..9e15f92 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +watch_file flake.nix +watch_file flake.lock +watch_dir nix + +use flake diff --git a/Cargo.lock b/Cargo.lock index 1a1878b..6251ee2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,7 +105,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "microfetch" -version = "0.3.2" +version = "0.3.3" dependencies = [ "color-eyre", "nix", diff --git a/Cargo.toml b/Cargo.toml index 3f9779b..9682a7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,24 @@ [package] name = "microfetch" -version = "0.3.2" +version = "0.3.3" edition = "2021" [dependencies] nix = {version = "0.29", features = ["fs", "hostname"]} color-eyre = { version = "0.6", default-features = false } +[profile.dev] +opt-level = 3 + [profile.release] strip = true opt-level = "z" lto = true codegen-units = 1 panic = "abort" + +[profile.profiler] +inherits = "release" +debug = true +split-debuginfo = "unpacked" +strip = "none" diff --git a/README.md b/README.md index 55f928c..decae73 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,25 @@ -# Microfetch +
+ https://deps.rs/repo/github/notashelf/microfetch + + +
-A stupidly simple fetch tool, written in Rust. Runs in a fraction of a second, -displays most nonsense people on r/unixporn care about. Aims to replace -fastfetch on my system, but probably not on yours. Though you are more than -welcome to use it on your system: it's fast. +

Microfetch

-![Demo](.github/assets/demo.png) +Stupidly simple, laughably fast fetch tool. Written in Rust for speed and ease +of maintainability. Runs in a _fraction of a millisecond_ and displays _most_ of +the nonsense you'd see posted on r/unixporn or other internet communities. Aims +to replace [fastfetch](https://github.com/fastfetch-cli/fastfetch) on my +personal system, but [probably not yours](#customizing). Though, you are more +than welcome to use it on your system: it's pretty [fast...](#benchmarks) + +

+ latest demo +

## Features @@ -20,7 +34,7 @@ welcome to use it on your system: it's fast. - Name - Version - Architecture - - Current shell (from $SHELL) + - Current shell (from $SHELL, trimmed if store path) - WM/Compositor and display backend - Memory Usage/Total Memory - Storage Usage/Total Storage (for `/` only) @@ -33,12 +47,17 @@ 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 | +| Command | Mean [ms] | Min [ms] | Max [ms] | Relative | +| :----------- | ----------: | -------: | -------: | -------------: | +| `microfetch` | 1.3 ± 0.0 | 1.3 | 1.4 | 1.00 | +| `pfetch` | 254.2 ± 4.8 | 246.7 | 264.9 | 191.97 ± 7.10 | +| `neofetch` | 735.4 ± 9.5 | 721.1 | 752.8 | 555.48 ± 19.08 | +| `fastfetch` | 31.9 ± 0.8 | 30.8 | 33.8 | 24.08 ± 0.98 | -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. +_As far as I'm concerned, Microfetch is faster than almost every fetch tool +there is. The only downside of using Rust is introducing more "bloated" +dependency trees and increasing build times. The latter is easily mitigated with +Nix's binary cache, though._ ## Customizing @@ -64,6 +83,14 @@ 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. +## Hacking + +A Nix flake is provided. `nix develop` to get started. Direnv users may simply +run `direnv allow` to get started. + +Non-nix users will need `cargo` and `gcc` installed on their system, see +`Cargo.toml` for available release profiles. + ## License Microfetch is licensed under [GPL3](LICENSE). See the license file for details. diff --git a/flake.nix b/flake.nix index 4ee4f5f..b5035c3 100644 --- a/flake.nix +++ b/flake.nix @@ -13,5 +13,9 @@ packages = forEachSystem (system: { default = pkgsForEach.${system}.callPackage ./nix/package.nix {}; }); + + devShells = forEachSystem (system: { + default = pkgsForEach.${system}.callPackage ./nix/shell.nix {}; + }); }; } diff --git a/nix/package.nix b/nix/package.nix index f2c6e4f..1a7dde3 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,17 +1,21 @@ { lib, rustPlatform, + stdenvAdapters, + llvm, }: let toml = (lib.importTOML ../Cargo.toml).package; pname = toml.name; inherit (toml) version; in - rustPlatform.buildRustPackage { + rustPlatform.buildRustPackage.override {stdenv = stdenvAdapters.useMoldLinker llvm.stdenv;} { + RUSTFLAGS = "-C link-arg=-fuse-ld=mold"; + inherit pname version; src = builtins.path { name = "${pname}-${version}"; - path = ../.; + path = lib.sources.cleanSource ../.; }; cargoLock.lockFile = ../Cargo.lock; diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..5efe65c --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,25 @@ +{ + mkShell, + rust-analyzer-unwrapped, + rustfmt, + clippy, + cargo, + rustc, + gcc, + rustPlatform, +}: +mkShell { + strictDeps = true; + + nativeBuildInputs = [ + cargo + rustc + gcc + + rust-analyzer-unwrapped + rustfmt + clippy + ]; + + env.RUST_SRC_PATH = "${rustPlatform.rustLibSrc}"; +} diff --git a/src/desktop.rs b/src/desktop.rs index 0b93ea5..9d72325 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -1,3 +1,4 @@ +use color_eyre::Result; use std::{env, io}; pub fn get_desktop_info() -> Result { diff --git a/src/main.rs b/src/main.rs index 713bf70..30fa78a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use crate::desktop::get_desktop_info; use crate::release::{get_os_pretty_name, get_system_info}; use crate::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname}; use crate::uptime::get_current; + use color_eyre::Report; use nix::sys::sysinfo::sysinfo; diff --git a/src/system.rs b/src/system.rs index bc770b7..551a833 100644 --- a/src/system.rs +++ b/src/system.rs @@ -1,3 +1,4 @@ +use color_eyre::Result; use nix::sys::statvfs::statvfs; use nix::sys::sysinfo::SysInfo; diff --git a/src/uptime.rs b/src/uptime.rs index b89cb42..6c44640 100644 --- a/src/uptime.rs +++ b/src/uptime.rs @@ -1,21 +1,10 @@ -use std::fs::File; -use std::io::{self, BufRead, BufReader}; -use std::path::Path; +use color_eyre::Result; +use nix::sys::sysinfo::sysinfo; +use std::io; pub fn get_current() -> Result { - let path = Path::new("/proc/uptime"); - let file = File::open(path)?; - let mut reader = BufReader::new(file); - - let mut line = String::new(); - reader.read_line(&mut line)?; - - let uptime_seconds: f64 = line - .split_whitespace() - .next() - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Failed to parse uptime"))? - .parse() - .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; + let info = sysinfo().map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + let uptime_seconds = info.uptime().as_secs_f64(); let total_minutes = (uptime_seconds / 60.0).round() as u64; let days = total_minutes / (60 * 24);