fix: Improvements to `starship configure` (#756)
- look for $VISUAL first, then $EDITOR, then the default - panic if we can't find the home dir
This commit is contained in:
parent
49d1c250d5
commit
11f73efa41
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue