├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── somefetch.png └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "colored" 7 | version = "3.0.0" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" 10 | dependencies = [ 11 | "windows-sys", 12 | ] 13 | 14 | [[package]] 15 | name = "somefetch" 16 | version = "0.2.1" 17 | dependencies = [ 18 | "colored", 19 | ] 20 | 21 | [[package]] 22 | name = "windows-sys" 23 | version = "0.59.0" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 26 | dependencies = [ 27 | "windows-targets", 28 | ] 29 | 30 | [[package]] 31 | name = "windows-targets" 32 | version = "0.52.6" 33 | source = "registry+https://github.com/rust-lang/crates.io-index" 34 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 35 | dependencies = [ 36 | "windows_aarch64_gnullvm", 37 | "windows_aarch64_msvc", 38 | "windows_i686_gnu", 39 | "windows_i686_gnullvm", 40 | "windows_i686_msvc", 41 | "windows_x86_64_gnu", 42 | "windows_x86_64_gnullvm", 43 | "windows_x86_64_msvc", 44 | ] 45 | 46 | [[package]] 47 | name = "windows_aarch64_gnullvm" 48 | version = "0.52.6" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 51 | 52 | [[package]] 53 | name = "windows_aarch64_msvc" 54 | version = "0.52.6" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 57 | 58 | [[package]] 59 | name = "windows_i686_gnu" 60 | version = "0.52.6" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 63 | 64 | [[package]] 65 | name = "windows_i686_gnullvm" 66 | version = "0.52.6" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 69 | 70 | [[package]] 71 | name = "windows_i686_msvc" 72 | version = "0.52.6" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 75 | 76 | [[package]] 77 | name = "windows_x86_64_gnu" 78 | version = "0.52.6" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 81 | 82 | [[package]] 83 | name = "windows_x86_64_gnullvm" 84 | version = "0.52.6" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 87 | 88 | [[package]] 89 | name = "windows_x86_64_msvc" 90 | version = "0.52.6" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 93 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "somefetch" 3 | version = "0.2.1" 4 | description = "Simple fetch for unix-like" 5 | authors = ["UnixAwesomes "] 6 | license = "BSD-3-Clause" 7 | edition = "2021" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | 11 | [dependencies] 12 | colored = "3.0.0" 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2024, UnixAwesomes 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![build result](https://build.opensuse.org/projects/home:sophr.temin/packages/somefetch/badge.svg?type=default)](https://build.opensuse.org/package/show/home:sophr.temin/somefetch) 2 | ## Simple fetch for unix-like systems 3 | 4 | ![Screenshot of somefetch](https://github.com/UnixAwesomes/somefetch/blob/master/somefetch.png) 5 | 6 | ## Install 7 | 8 | ``` 9 | git clone https://github.com/UnixAwesomes/somefetch 10 | cd somefetch 11 | cargo build --release 12 | ``` 13 | 14 | Debian Package Build Instructions: [link](https://github.com/OctoBanon-Main/somefetch-debian) 15 | 16 | ### Available in openSUSE 17 | 18 | link: [click](https://software.opensuse.org//download.html?project=home%3Asophr.temin&package=somefetch) 19 | 20 | package(rpm): [click](somefetch-0.1.0-2.1.x86_64.rpm) 21 | -------------------------------------------------------------------------------- /somefetch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnixAwesomes/somefetch/bcc14c4c5a8a36e91db4b7e4a2faeab9c0b29c07/somefetch.png -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use colored::*; 2 | use std::env; 3 | use std::str; 4 | use std::process::Command; 5 | 6 | fn get_os_name() -> Option { 7 | #[cfg(any(target_os = "linux", target_os = "android"))] 8 | { 9 | get_info_name("-rm") 10 | } 11 | #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] 12 | { 13 | get_info_name("-srm") 14 | } 15 | #[cfg(target_os = "freebsd")] 16 | { 17 | get_info_name("-rom") 18 | } 19 | #[cfg(target_os = "illumos")] 20 | { 21 | get_info_name("-v") 22 | } 23 | #[cfg(target_os = "macos")] 24 | { 25 | get_info_name("-sr") 26 | } 27 | } 28 | 29 | fn get_info_name(args: &str) -> Option { 30 | let output = Command::new("uname").arg(args).output().ok()?; 31 | Some(String::from_utf8(output.stdout).ok()?.trim().to_string()) 32 | } 33 | 34 | fn get_host_name() -> Option { 35 | let output = Command::new("hostname").output().ok()?; 36 | Some(String::from_utf8(output.stdout).ok()?.trim().to_string()) 37 | } 38 | 39 | fn get_cpu_name() -> Option { 40 | #[cfg(any(target_os = "freebsd", target_os = "openbsd"))] 41 | { 42 | let output = Command::new("sysctl") 43 | .args(["-n", "hw.model"]) 44 | .output() 45 | .ok()?; 46 | Some(String::from_utf8(output.stdout).ok()?.trim().to_string()) 47 | } 48 | 49 | #[cfg(target_os = "netbsd")] 50 | { 51 | let output = Command::new("sysctl") 52 | .args(["-n", "machdep.cpu_brand"]) 53 | .output() 54 | .ok()?; 55 | Some(String::from_utf8(output.stdout).ok()?.trim().to_string()) 56 | } 57 | 58 | #[cfg(target_os = "macos")] 59 | { 60 | let output = Command::new("sysctl") 61 | .args(["-n", "machdep.cpu.brand_string"]) 62 | .output() 63 | .ok()?; 64 | Some(String::from_utf8(output.stdout).ok()?.trim().to_string()) 65 | } 66 | 67 | #[cfg(target_os = "illumos")] 68 | { 69 | let output = Command::new("kstat") 70 | .args(["-p", "cpu_info:::brand"]) 71 | .output() 72 | .ok()?; 73 | 74 | let output_str = str::from_utf8(&output.stdout).ok()?; 75 | 76 | for line in output_str.lines() { 77 | if let Some((_, model)) = line.split_once('\t') { 78 | return Some(model.trim().to_string()); 79 | } 80 | } 81 | None 82 | } 83 | 84 | #[cfg(any(target_os = "linux", target_os = "android"))] 85 | { 86 | let info = std::fs::read_to_string("/proc/cpuinfo").ok()?; 87 | #[cfg(target_os = "android")] 88 | let cpu_string = "Hardware"; 89 | #[cfg(target_os = "linux")] 90 | let cpu_string = "model name"; 91 | for line in info.lines() { 92 | if line.starts_with(cpu_string) { 93 | let (_, name) = line.split_once(':')?; 94 | return Some(name.trim().to_owned()); 95 | } 96 | } 97 | None 98 | } 99 | } 100 | 101 | fn get_shell() -> String { 102 | env::var("SHELL") 103 | .ok() 104 | .and_then(|s| s.split('/').last().map(|s| s.to_string())) 105 | .unwrap_or_else(|| "Unknown".into()) 106 | } 107 | 108 | fn get_pkgs() -> String { 109 | let package_managers: &[(&str, &[&str], &str)] = &[ 110 | ("xbps-query", &["-l"][..], "xbps"), 111 | ("apk", &["info"], "apk"), 112 | ("rpm", &["-qa"], "rpm"), 113 | ("flatpak", &["list"], "flatpak"), 114 | ("dpkg-query", &["-f", "'.\\n'", "-W"], "apt"), 115 | ("pacman", &["-Q", "-q"], "pacman"), 116 | ("qlist", &["-I"], "portage"), 117 | ("pkg", &["info"], "pkg"), 118 | ("brew", &["list"], "homebrew"), 119 | ("pkgin", &["info"], "pkgin"), 120 | ("pkg_info", &[], "pkg_info"), 121 | ("snap", &["list"], "snap"), 122 | ("eopkg", &["li"], "eopkg"), 123 | ("opkg", &["list-installed"], "opkg"), 124 | ("nix-user-pkgs", &[], "nix-user"), 125 | ("nix-store", &["-qR", "/run/current-system/sw"], "nix-system"), 126 | ]; 127 | 128 | package_managers 129 | .iter() 130 | .filter_map(|(cmd, args, tag)| { 131 | Command::new(cmd) 132 | .args(*args) 133 | .output() 134 | .ok() 135 | .and_then(|output| { 136 | let count = String::from_utf8_lossy(&output.stdout) 137 | .lines() 138 | .count(); 139 | (count > 0).then(|| format!("{}({})", count, tag)) 140 | }) 141 | }) 142 | .collect::>() 143 | .join(", ") 144 | } 145 | 146 | fn main() { 147 | let os_name = get_os_name().unwrap_or("Unknown".to_string()); 148 | let cpu = get_cpu_name().unwrap_or("Unknown".to_string()); 149 | let hostname = get_host_name().unwrap_or("Unknown".to_string()); 150 | let shell = get_shell(); 151 | let desktop = env::var("XDG_CURRENT_DESKTOP").unwrap_or_else(|_| "Unknown".to_string()); 152 | 153 | 154 | println!( 155 | " 156 | {} 157 | 158 | {} {} 159 | {} {} 160 | {} {} 161 | {} {} 162 | {} {} 163 | ", 164 | "~ system info ~".bright_cyan(), 165 | "host".bright_yellow(), 166 | hostname, 167 | "kernel".bright_green(), 168 | os_name, 169 | "pkgs".bright_magenta(), 170 | get_pkgs(), 171 | "shell".bright_blue(), 172 | shell, 173 | "de/wm".bright_red(), 174 | desktop, 175 | ); 176 | 177 | println!( 178 | " {} 179 | 180 | {} {} 181 | ", 182 | "~ hardware info ~".bright_cyan(), 183 | "cpu".bright_green(), 184 | cpu, 185 | ); 186 | } 187 | --------------------------------------------------------------------------------