From 5a50f9c44406a19b28ced8770c8dba9de3751a75 Mon Sep 17 00:00:00 2001 From: shibedrill <53824200+shibedrill@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:42:59 -0500 Subject: [PATCH] Refactored stuff with Clippy --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 17 ++++++++++++----- src/main.rs | 6 +++--- src/terminal.rs | 21 +++++++++------------ 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87acd3f..96f3cf9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -348,7 +348,7 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "oxidefetch" -version = "1.4.7" +version = "1.4.8" dependencies = [ "byte-unit", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 785a8f8..a835aef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "oxidefetch" description = "A fast, cross platform Fetch program for your terminal" -version = "1.4.7" +version = "1.4.8" edition = "2021" authors = [ "NamedNeon", "shibedrill" ] license = "MIT" diff --git a/README.md b/README.md index b478cef..460e069 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# oxidefetch 1.4.7 +# oxidefetch 1.4.8 Fully cross platform Neofetch clone written in Rust. Up to 25 times faster than Neofetch! ![alt text](image.png "Example output of OxideFetch on a WSL2 Arch Linux host") @@ -29,13 +29,18 @@ OxideFetch can display all of the following information: Also, the field-titles feature can be enabled at compile-time, which will display the name of each field in white before the information within that field. By default, it is disabled. ### Installation -Download a binary for your platform, and place it in your PATH. +Download a binary for your platform, and place it in your `$PATH`. Currently, only Windows (x86_64, gnu/msvc) and Linux (x86_64/aarch64, gnu/musl) have binaries available. If you want a binary for another platform, you will have to follow the instructions to build from source. ### Dependencies #### Build/Install -To build Oxidefetch, you need Cargo. You can use Cargo to automatically build and install it like so: -`cargo install --git https://github.com/shibedrill/oxidefetch`. (Alternatively, you can get it from the Crates repos, using `cargo install oxidefetch`. But it might be slightly out of date.) From there, it *should* be in your `$PATH`. If not, add `source ~/.cargo/env` to your profile, or add `~/.cargo/bin` to your `$PATH`. If you do not already have Cargo installed on your system, you can do so by installing Rustup- either via the [instructions on their website](https://doc.rust-lang.org/cargo/getting-started/installation.html "instructions on their website") or via your system package manager. You will also probably need a C compiler and a build system- most likely CMake or GNU Make. You will be prompted to install these if they're not found during compilation. +To build Oxidefetch, you need Cargo. If you do not already have Cargo installed on your system, you can do so by installing Rustup- either via the [instructions on their website](https://doc.rust-lang.org/cargo/getting-started/installation.html "instructions on their website") or via your system package manager. +You will also probably need a C/C++ compiler and a build system- most likely CMake and Visual Studio Build Tools, or GNU Make and the GNU compiler collection. You will be prompted to install these if they're not found during compilation. +You can use Cargo, once it's installed, to automatically build and install Oxidefetch like so: +`cargo install --git https://github.com/shibedrill/oxidefetch`. +Alternatively, you can get it from the Crates repos, using `cargo install oxidefetch`. But it might be slightly out of date. +From there, it *should* be in your `$PATH`. If not, add `source ~/.cargo/env` to your profile, or add `~/.cargo/bin` to your `$PATH`. + #### Runtime There's only a couple runtime dependencies for this project. 1: `sh` shell installed for GPU detection on \*nix systems. @@ -45,7 +50,8 @@ GPU detection runs on Windows without any dependencies.) 3: Nerd fonts symbols are used in the output. Install a patched font on your system, or patch an already installed font. ### How you can help with the project -I need to verify the output of the OS information detection libraries I'm pulling in. To do this, I need the help of people with varying types of systems. I've tested a few, but there's some I'm unable to test. To help, you can kindly clone this repo, and inside the folder, run `cargo test -- --nocapture`, and send the resultant `test_output.txt` file to my noreply email address, or directly to me on Discord at `@shibedrill`. This program does NOT collect information regarding your real name, IP, location, hardware serial numbers, etc. You can look at the file it generates to be sure- it's all plaintext, babey. +I need to verify the output of the OS information detection libraries I'm pulling in. To do this, I need the help of people with varying types of systems. I've tested a few, but there's some I'm unable to test. To help, you can kindly clone this repo, and inside the folder, run `cargo test -- --nocapture`, and send the resultant `test_output.txt` file to my noreply email address, or directly to me on Discord at `@shibedrill`. This program does NOT collect information regarding your real name, IP, location, hardware serial numbers, etc. You can look at the file it generates to be sure- it's all plaintext, babey. Also, consider contributing to [libpci-rs](https://github.com/namedneon/libpci-rs), which will eventually take responsibility for the GPU detection. + #### Tested distributions/platforms: - Alma Linux - Alpine Linux @@ -100,6 +106,7 @@ No weird quirks to report at this time. **1.4.5:** Minor changes to system color detection. Removed all warnings. **1.4.6:** Cargo formatting applied to all files. Mild string reformatting in print statements. **1.4.7:** Removed several `unwrap()` calls. Changed debug output to serialize to RON. +**1.4.8:** Applied Clippy suggestions. Added stuff to README. ### License This software is covered by the MIT license. See license.txt for details. diff --git a/src/main.rs b/src/main.rs index 6901ebf..8b91a13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,10 +28,10 @@ use crate::terminal::get_terminal; use byte_unit::*; use chrono::*; use colored::*; -use compound_duration; + use std::env; use sysinfo::*; -use whoami; + #[cfg(test)] use serde::Serialize; @@ -141,7 +141,7 @@ impl Information { shell: { let var = env::var("SHELL"); if let Ok(var_ok) = var { - Some(format!("{}", var_ok.split('/').last().unwrap())) + Some(var_ok.split('/').last().unwrap().to_string()) } else { None } diff --git a/src/terminal.rs b/src/terminal.rs index 6fad81f..beab46d 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -56,16 +56,13 @@ macro_rules! match_env_to_terminal { pub fn get_terminal() -> Option { // Match Apple terminals. - match env::var("TERM_PROGRAM") { - Ok(f) => { - return match f.as_str() { - "iTerm.app" => Some("iTerm2".to_string()), - "Terminal.app" => Some("Apple Terminal".to_string()), - "Hyper.app" => Some("Hyper".to_string()), - _ => None, - }; - } - Err(_) => (), + if let Ok(f) = env::var("TERM_PROGRAM") { + return match f.as_str() { + "iTerm.app" => Some("iTerm2".to_string()), + "Terminal.app" => Some("Apple Terminal".to_string()), + "Hyper.app" => Some("Hyper".to_string()), + _ => None, + }; }; match_env_to_terminal!("ConEmuPID", "ConEmu"); @@ -79,7 +76,7 @@ pub fn get_terminal() -> Option { Ok(f) => f, Err(_) => "".to_string(), }; - let shell_name = shell.split("/").last().unwrap(); + let shell_name = shell.split('/').last().unwrap(); #[allow(unused_assignments)] let mut name: Option = None; @@ -137,7 +134,7 @@ pub fn get_terminal() -> Option { return match name { Some(f) => { // Remove the file extension. - let mut res = f.split(".").nth(0).unwrap().to_string(); + let mut res = f.split('.').next().unwrap().to_string(); // Try to get a "prettier name". if PRETTY_NAMES.contains_key(res.as_str()) {