2019-12-18 21:09:36 +00:00
|
|
|
use std::env;
|
2019-12-20 14:55:53 +00:00
|
|
|
use std::ffi::OsString;
|
2019-12-18 21:09:36 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
const STD_EDITOR: &str = "vi";
|
|
|
|
|
|
|
|
pub fn edit_configuration() {
|
|
|
|
let editor = get_editor();
|
|
|
|
let config_path = get_config_path();
|
|
|
|
|
|
|
|
Command::new(editor)
|
|
|
|
.arg(config_path)
|
|
|
|
.status()
|
|
|
|
.expect("failed to open file");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_editor() -> String {
|
2019-12-20 14:55:53 +00:00
|
|
|
let editor = env::var("VISUAL").or_else(|_| env::var("EDITOR"));
|
|
|
|
editor.unwrap_or_else(|_| STD_EDITOR.to_string())
|
2019-12-18 21:09:36 +00:00
|
|
|
}
|
|
|
|
|
2019-12-20 14:55:53 +00:00
|
|
|
fn get_config_path() -> OsString {
|
|
|
|
dirs::home_dir()
|
|
|
|
.expect("Couldn't find home directory")
|
|
|
|
.join(".config/starship.toml")
|
|
|
|
.as_os_str()
|
|
|
|
.to_owned()
|
2019-12-18 21:09:36 +00:00
|
|
|
}
|