mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-11-03 15:27:35 +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> {
|
fn main() -> Result<(), Report> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
|
||||||
|
let utsname = nix::sys::utsname::uname()?;
|
||||||
let fields = Fields {
|
let fields = Fields {
|
||||||
user_info: get_username_and_hostname(),
|
user_info: get_username_and_hostname(&utsname),
|
||||||
os_name: get_os_pretty_name()?,
|
os_name: get_os_pretty_name()?,
|
||||||
kernel_version: get_system_info()?,
|
kernel_version: get_system_info(&utsname)?,
|
||||||
shell: get_shell(),
|
shell: get_shell(),
|
||||||
desktop: get_desktop_info(),
|
desktop: get_desktop_info(),
|
||||||
uptime: get_current()?,
|
uptime: get_current()?,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
|
use nix::sys::utsname::UtsName;
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, Read},
|
io::{self, Read},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_system_info() -> nix::Result<String> {
|
pub fn get_system_info(utsname: &UtsName) -> nix::Result<String> {
|
||||||
let utsname = nix::sys::utsname::uname()?;
|
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{} {} ({})",
|
"{} {} ({})",
|
||||||
utsname.sysname().to_str().unwrap_or("Unknown"),
|
utsname.sysname().to_str().unwrap_or("Unknown"),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use nix::sys::statvfs::statvfs;
|
use nix::sys::{statvfs::statvfs, utsname::UtsName};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
|
|
@ -9,10 +9,13 @@ use std::{
|
||||||
|
|
||||||
use crate::colors::{CYAN, GREEN, RED, RESET, YELLOW};
|
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 username = env::var("USER").unwrap_or("unknown_user".to_string());
|
||||||
let hostname = nix::unistd::gethostname().unwrap_or("unknown_host".to_string().into());
|
let hostname = utsname
|
||||||
let hostname = hostname.to_string_lossy();
|
.nodename()
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or("unknown_host")
|
||||||
|
.to_string();
|
||||||
|
|
||||||
format!("{YELLOW}{username}{RED}@{GREEN}{hostname}")
|
format!("{YELLOW}{username}{RED}@{GREEN}{hostname}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue