diff --git a/src/configure.rs b/src/configure.rs index f4fb5bf1..8f3e4b05 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -1,7 +1,7 @@ use std::env; +use std::ffi::OsString; use std::process::Command; -const UNKNOWN_CONFIG: &str = ""; const STD_EDITOR: &str = "vi"; pub fn edit_configuration() { @@ -15,23 +15,14 @@ pub fn edit_configuration() { } fn get_editor() -> String { - match env::var("EDITOR") { - Ok(val) => val, - Err(_) => STD_EDITOR.to_string(), - } + let editor = env::var("VISUAL").or_else(|_| env::var("EDITOR")); + editor.unwrap_or_else(|_| STD_EDITOR.to_string()) } -fn get_config_path() -> String { - let home_dir = dirs::home_dir(); - - if home_dir.is_none() { - return UNKNOWN_CONFIG.to_string(); - } - - let path = home_dir.unwrap().join(".config/starship.toml"); - - match path.to_str() { - Some(p) => String::from(p), - None => UNKNOWN_CONFIG.to_string(), - } +fn get_config_path() -> OsString { + dirs::home_dir() + .expect("Couldn't find home directory") + .join(".config/starship.toml") + .as_os_str() + .to_owned() }