From 11f73efa4106e9179810b00a18f57f71e531b781 Mon Sep 17 00:00:00 2001 From: AppleTheGolden Date: Fri, 20 Dec 2019 15:55:53 +0100 Subject: [PATCH] fix: Improvements to `starship configure` (#756) - look for $VISUAL first, then $EDITOR, then the default - panic if we can't find the home dir --- src/configure.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) 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() }