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::env;
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
const UNKNOWN_CONFIG: &str = "<unknown config>";
|
|
||||||
const STD_EDITOR: &str = "vi";
|
const STD_EDITOR: &str = "vi";
|
||||||
|
|
||||||
pub fn edit_configuration() {
|
pub fn edit_configuration() {
|
||||||
|
@ -15,23 +15,14 @@ pub fn edit_configuration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_editor() -> String {
|
fn get_editor() -> String {
|
||||||
match env::var("EDITOR") {
|
let editor = env::var("VISUAL").or_else(|_| env::var("EDITOR"));
|
||||||
Ok(val) => val,
|
editor.unwrap_or_else(|_| STD_EDITOR.to_string())
|
||||||
Err(_) => STD_EDITOR.to_string(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_config_path() -> String {
|
fn get_config_path() -> OsString {
|
||||||
let home_dir = dirs::home_dir();
|
dirs::home_dir()
|
||||||
|
.expect("Couldn't find home directory")
|
||||||
if home_dir.is_none() {
|
.join(".config/starship.toml")
|
||||||
return UNKNOWN_CONFIG.to_string();
|
.as_os_str()
|
||||||
}
|
.to_owned()
|
||||||
|
|
||||||
let path = home_dir.unwrap().join(".config/starship.toml");
|
|
||||||
|
|
||||||
match path.to_str() {
|
|
||||||
Some(p) => String::from(p),
|
|
||||||
None => UNKNOWN_CONFIG.to_string(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue