summaryrefslogtreecommitdiffstats
path: root/src/configure.rs
diff options
context:
space:
mode:
authorAppleTheGolden <scotsbox@protonmail.com>2019-12-20 15:55:53 +0100
committerMatan Kushner <hello@matchai.me>2019-12-20 09:55:53 -0500
commit11f73efa4106e9179810b00a18f57f71e531b781 (patch)
treeadef07a7c6e4cf29af238505652749fdf7b1f124 /src/configure.rs
parent49d1c250d55e4e1d869c4d2212950e8d48bb0be9 (diff)
fix: Improvements to `starship configure` (#756)
- look for $VISUAL first, then $EDITOR, then the default - panic if we can't find the home dir
Diffstat (limited to 'src/configure.rs')
-rw-r--r--src/configure.rs27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/configure.rs b/src/configure.rs
index f4fb5bf1d..8f3e4b054 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 = "<unknown config>";
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()
}