diff --git a/Cargo.toml b/Cargo.toml index 0ff775a..b7e8345 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ path = "src/make_prompt.rs" [dependencies] git2="*" +gethostname="*" diff --git a/src/make_prompt.rs b/src/make_prompt.rs index 544f00a..1960308 100644 --- a/src/make_prompt.rs +++ b/src/make_prompt.rs @@ -2,6 +2,8 @@ use std::fs::File; use std::io::Read; use std::io::BufReader; use std::io::BufRead; +use gethostname::gethostname; +use std::ffi::OsString; fn fixed_width(input: &String, len: usize) -> String { @@ -173,12 +175,12 @@ fn getenv(varname: &str) -> String { match std::env::var(varname) { - Ok(hostname) => hostname, - Err(_) => "".to_string() + Ok(var) => var, + Err(_err) => {"".to_string()} } } -fn main() +fn main() ->Result<(), OsString> { const SH_GREEN: &str = "1;32"; const SH_RED: &str = "01;31"; @@ -246,7 +248,7 @@ fn main() } { print!("{}{}", shell_color_str(&"╞[", SH_GREEN) - , shell_color_str(&fixed_width(&getenv("HOSTNAME"), 13), SH_CYAN)); + , shell_color_str(&fixed_width(&gethostname().into_string()?, 13), SH_CYAN)); print!("{}{}", shell_color_str(&"|", SH_GREEN) , shell_color_str(&fixed_width(&getenv("USER"), 13), SH_RED)); print!("{}{}", shell_color_str(&"|", SH_GREEN) @@ -265,4 +267,5 @@ fn main() { print!("{} {} ", shell_color_str(&"└", SH_GREEN), shell_color_str(&"$", SH_PURPLE)); } + Ok(()) }