mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-11-02 23:16:37 +00:00
perf: get rid of duplicate uname syscall
This commit is contained in:
parent
9842f3f0c0
commit
577012ff51
3 changed files with 12 additions and 8 deletions
|
|
@ -17,10 +17,11 @@ use color_eyre::Report;
|
|||
fn main() -> Result<(), Report> {
|
||||
color_eyre::install()?;
|
||||
|
||||
let utsname = nix::sys::utsname::uname()?;
|
||||
let fields = Fields {
|
||||
user_info: get_username_and_hostname(),
|
||||
user_info: get_username_and_hostname(&utsname),
|
||||
os_name: get_os_pretty_name()?,
|
||||
kernel_version: get_system_info()?,
|
||||
kernel_version: get_system_info(&utsname)?,
|
||||
shell: get_shell(),
|
||||
desktop: get_desktop_info(),
|
||||
uptime: get_current()?,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use color_eyre::Result;
|
||||
use nix::sys::utsname::UtsName;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{self, Read},
|
||||
};
|
||||
|
||||
pub fn get_system_info() -> nix::Result<String> {
|
||||
let utsname = nix::sys::utsname::uname()?;
|
||||
pub fn get_system_info(utsname: &UtsName) -> nix::Result<String> {
|
||||
Ok(format!(
|
||||
"{} {} ({})",
|
||||
utsname.sysname().to_str().unwrap_or("Unknown"),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use color_eyre::Result;
|
||||
use nix::sys::statvfs::statvfs;
|
||||
use nix::sys::{statvfs::statvfs, utsname::UtsName};
|
||||
|
||||
use std::{
|
||||
env,
|
||||
|
|
@ -9,10 +9,13 @@ use std::{
|
|||
|
||||
use crate::colors::{CYAN, GREEN, RED, RESET, YELLOW};
|
||||
|
||||
pub fn get_username_and_hostname() -> String {
|
||||
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
||||
let username = env::var("USER").unwrap_or("unknown_user".to_string());
|
||||
let hostname = nix::unistd::gethostname().unwrap_or("unknown_host".to_string().into());
|
||||
let hostname = hostname.to_string_lossy();
|
||||
let hostname = utsname
|
||||
.nodename()
|
||||
.to_str()
|
||||
.unwrap_or("unknown_host")
|
||||
.to_string();
|
||||
|
||||
format!("{YELLOW}{username}{RED}@{GREEN}{hostname}")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue