mirror of
				https://github.com/NotAShelf/microfetch.git
				synced 2025-10-30 22:02:38 +00:00 
			
		
		
		
	Compare commits
	
		
			No commits in common. "927f6077b4b78cd112bc6932aab5287edc413ce8" and "17152f9d142ce0badde14018703bb1590e3df947" have entirely different histories.
		
	
	
		
			
				927f6077b4
			
			...
			
				17152f9d14
			
		
	
		
					 3 changed files with 58 additions and 49 deletions
				
			
		|  | @ -4,7 +4,7 @@ version = "0.3.3" | |||
| edition = "2021" | ||||
| 
 | ||||
| [dependencies] | ||||
| nix = { version = "0.29", features = ["fs", "hostname", "feature"] } | ||||
| nix = {version = "0.29", features = ["fs", "hostname"]} | ||||
| color-eyre = { version = "0.6", default-features = false } | ||||
| 
 | ||||
| [profile.dev] | ||||
|  |  | |||
							
								
								
									
										72
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										72
									
								
								src/main.rs
									
										
									
									
									
								
							|  | @ -16,40 +16,43 @@ use nix::sys::sysinfo::sysinfo; | |||
| fn main() -> Result<(), Report> { | ||||
|     color_eyre::install()?; | ||||
| 
 | ||||
|     let fields = Fields { | ||||
|         user_info: get_username_and_hostname()?, | ||||
|         os_name: get_os_pretty_name()?, | ||||
|         kernel_version: get_system_info()?, | ||||
|         shell: get_shell()?, | ||||
|         uptime: get_current()?, | ||||
|         window_manager: get_desktop_info()?, | ||||
|         memory_usage: get_memory_usage(sysinfo()?), | ||||
|         storage: get_root_disk_usage()?, | ||||
|         colors: print_dots()?, | ||||
|     }; | ||||
|     let user_info = get_username_and_hostname()?; | ||||
|     let os_name = get_os_pretty_name()?; | ||||
|     let kernel_version = get_system_info()?; | ||||
|     let shell = get_shell()?; | ||||
|     let uptime = get_current()?; | ||||
|     let window_manager = get_desktop_info()?; | ||||
|     let sys_info = sysinfo()?; | ||||
|     let memory_usage = get_memory_usage(sys_info); | ||||
|     let storage = get_root_disk_usage()?; | ||||
|     let colors = print_dots()?; | ||||
| 
 | ||||
|     print_system_info(&fields); | ||||
|     print_system_info( | ||||
|         &user_info, | ||||
|         &os_name, | ||||
|         &kernel_version, | ||||
|         &shell, | ||||
|         &uptime, | ||||
|         &window_manager, | ||||
|         &memory_usage, | ||||
|         &storage, | ||||
|         &colors, | ||||
|     ); | ||||
| 
 | ||||
|     Ok(()) | ||||
| } | ||||
| 
 | ||||
| // Struct to hold all the fields we need to print
 | ||||
| // helps avoid clippy warnings about argument count
 | ||||
| // and makes it easier to pass around, though its
 | ||||
| // not like we need to
 | ||||
| struct Fields { | ||||
|     user_info: String, | ||||
|     os_name: String, | ||||
|     kernel_version: String, | ||||
|     shell: String, | ||||
|     uptime: String, | ||||
|     window_manager: String, | ||||
|     memory_usage: String, | ||||
|     storage: String, | ||||
|     colors: String, | ||||
| } | ||||
| 
 | ||||
| fn print_system_info(fields: &Fields) { | ||||
| fn print_system_info( | ||||
|     user_info: &str, | ||||
|     os_name: &str, | ||||
|     kernel_version: &str, | ||||
|     shell: &str, | ||||
|     uptime: &str, | ||||
|     window_manager: &str, | ||||
|     memory_usage: &str, | ||||
|     storage: &str, | ||||
|     colors: &str, | ||||
| ) { | ||||
|     println!( | ||||
|         " | ||||
|  {CYAN}     ▟█▖    {BLUE}▝█▙ ▗█▛          {user_info} ~{RESET} | ||||
|  | @ -61,15 +64,6 @@ fn print_system_info(fields: &Fields) { | |||
|  {BLUE}  ▝█▛  {CYAN}██▖{BLUE}▗▄▄▄▄▄▄▄▄▄▄▄       {CYAN}  {BLUE}Memory{RESET}        {memory_usage} | ||||
|  {BLUE}   ▝  {CYAN}▟█▜█▖{BLUE}▀▀▀▀▀██▛▀▀▘       {CYAN}  {BLUE}Storage (/){RESET}   {storage} | ||||
|  {CYAN}     ▟█▘ ▜█▖    {BLUE}▝█▛          {CYAN}  {BLUE}Colors{RESET}        {colors} | ||||
| ",
 | ||||
|         user_info = fields.user_info, | ||||
|         os_name = fields.os_name, | ||||
|         kernel_version = fields.kernel_version, | ||||
|         shell = fields.shell, | ||||
|         uptime = fields.uptime, | ||||
|         window_manager = fields.window_manager, | ||||
|         memory_usage = fields.memory_usage, | ||||
|         storage = fields.storage, | ||||
|         colors = fields.colors, | ||||
|     " | ||||
|     ); | ||||
| } | ||||
|  |  | |||
|  | @ -1,15 +1,30 @@ | |||
| use color_eyre::Result; | ||||
| use std::fs::read_to_string; | ||||
| use std::fs::{self, read_to_string}; | ||||
| use std::io; | ||||
| 
 | ||||
| pub fn get_system_info() -> nix::Result<String> { | ||||
|     let utsname = nix::sys::utsname::uname()?; | ||||
|     Ok(format!( | ||||
|         "{} {} ({})", | ||||
|         utsname.sysname().to_str().unwrap_or("Unknown"), | ||||
|         utsname.release().to_str().unwrap_or("Unknown"), | ||||
|         utsname.machine().to_str().unwrap_or("Unknown") | ||||
|     )) | ||||
| // Try to detect OS type as accurately as possible and without depending on uname.
 | ||||
| // /etc/os-release should generally imply Linux, and /etc/bsd-release would imply BSD system.
 | ||||
| fn detect_os() -> Result<&'static str, io::Error> { | ||||
|     if fs::metadata("/etc/os-release").is_ok() || fs::metadata("/usr/lib/os-release").is_ok() { | ||||
|         Ok("Linux") | ||||
|     } else if fs::metadata("/etc/rc.conf").is_ok() || fs::metadata("/etc/bsd-release").is_ok() { | ||||
|         Ok("BSD") | ||||
|     } else { | ||||
|         Ok("Unknown") | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| pub fn get_system_info() -> Result<String, io::Error> { | ||||
|     let system = detect_os()?; | ||||
| 
 | ||||
|     let kernel_release = read_to_string("/proc/sys/kernel/osrelease")?; | ||||
|     let kernel_release = kernel_release.trim(); | ||||
| 
 | ||||
|     let architecture = read_to_string("/proc/sys/kernel/arch")?; | ||||
|     let architecture = architecture.trim(); | ||||
| 
 | ||||
|     let result = format!("{system} {kernel_release} ({architecture})"); | ||||
|     Ok(result) | ||||
| } | ||||
| 
 | ||||
| pub fn get_os_pretty_name() -> Result<String, io::Error> { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue