add mac support?
This commit is contained in:
1 file changed
+31
-9
+31
-9
@@ -1,5 +1,6 @@
|
||||
use std::env;
|
||||
use std::fs::read_to_string;
|
||||
use std::process::Command;
|
||||
|
||||
fn print_logo() {
|
||||
print!(
|
||||
@@ -35,9 +36,15 @@ fn get_os() -> String {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "unix")]
|
||||
#[cfg(target_os = "macos")]
|
||||
fn get_os() -> String {
|
||||
return String::new();
|
||||
let output = Command::new("sw_vers").arg("-productVersion").output().ok();
|
||||
if let Some(out) = output {
|
||||
let version = String::from_utf8_lossy(&out.stdout).trim().to_string();
|
||||
format!("macOS {}", version)
|
||||
} else {
|
||||
"macOS".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
@@ -48,11 +55,22 @@ fn get_shell() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn get_host() -> String {
|
||||
read_to_string("/etc/hostname").unwrap().trim().to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn get_host() -> String {
|
||||
let output = Command::new("hostname").output().ok();
|
||||
if let Some(out) = output {
|
||||
String::from_utf8_lossy(&out.stdout).trim().to_string()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn get_kernel() -> String {
|
||||
let kernel = read_to_string("/proc/sys/kernel/osrelease")
|
||||
@@ -62,9 +80,15 @@ fn get_kernel() -> String {
|
||||
format!("Linux {}", kernel)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
#[cfg(target_os = "macos")]
|
||||
fn get_kernel() -> String {
|
||||
String::new()
|
||||
let output = Command::new("uname").arg("-r").output().ok();
|
||||
if let Some(out) = output {
|
||||
let version = String::from_utf8_lossy(&out.stdout).trim().to_string();
|
||||
format!("Darwin {}", version)
|
||||
} else {
|
||||
"Darwin".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_terminal() -> String {
|
||||
@@ -110,10 +134,8 @@ fn get_memory() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn get_memory() -> String {
|
||||
String::new()
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
fn get_memory() -> String { String::new() }
|
||||
|
||||
fn main() {
|
||||
let os = get_os();
|
||||
|
||||
Reference in new issue
Block a user