mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-26 19:40:20 +00:00
feat: Implement starship configure
command (#751)
This commit is contained in:
parent
c82aeb70db
commit
a4c5c00a73
37
src/configure.rs
Normal file
37
src/configure.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
const UNKNOWN_CONFIG: &str = "<unknown config>";
|
||||||
|
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 {
|
||||||
|
match env::var("EDITOR") {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_) => 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(),
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ extern crate clap;
|
|||||||
mod bug_report;
|
mod bug_report;
|
||||||
mod config;
|
mod config;
|
||||||
mod configs;
|
mod configs;
|
||||||
|
mod configure;
|
||||||
mod context;
|
mod context;
|
||||||
mod init;
|
mod init;
|
||||||
mod module;
|
mod module;
|
||||||
@ -110,6 +111,7 @@ fn main() {
|
|||||||
.arg(&keymap_arg)
|
.arg(&keymap_arg)
|
||||||
.arg(&jobs_arg),
|
.arg(&jobs_arg),
|
||||||
)
|
)
|
||||||
|
.subcommand(SubCommand::with_name("configure").about("Edit the starship configuration"))
|
||||||
.subcommand(SubCommand::with_name("bug-report").about(
|
.subcommand(SubCommand::with_name("bug-report").about(
|
||||||
"Create a pre-populated GitHub issue with information about your configuration",
|
"Create a pre-populated GitHub issue with information about your configuration",
|
||||||
))
|
))
|
||||||
@ -137,6 +139,7 @@ fn main() {
|
|||||||
print::module(module_name, sub_m.clone());
|
print::module(module_name, sub_m.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
("configure", Some(_)) => configure::edit_configuration(),
|
||||||
("bug-report", Some(_)) => bug_report::create(),
|
("bug-report", Some(_)) => bug_report::create(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user