summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDominik Braun <dominikbraun1997@web.de>2019-12-18 22:09:36 +0100
committerMatan Kushner <hello@matchai.me>2019-12-18 16:09:36 -0500
commita4c5c00a73598098ffb30f3bebe4781ee2601b36 (patch)
tree55e044ac991ddf820fc9407dc54883e44cd32f2f /src
parentc82aeb70db7e8ad3d1ca984eea52c76de35daf39 (diff)
feat: Implement `starship configure` command (#751)
Diffstat (limited to 'src')
-rw-r--r--src/configure.rs37
-rw-r--r--src/main.rs3
2 files changed, 40 insertions, 0 deletions
diff --git a/src/configure.rs b/src/configure.rs
new file mode 100644
index 000000000..f4fb5bf1d
--- /dev/null
+++ b/src/configure.rs
@@ -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(),
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 47c7e80ab..2f995f0df 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@ extern crate clap;
mod bug_report;
mod config;
mod configs;
+mod configure;
mod context;
mod init;
mod module;
@@ -110,6 +111,7 @@ fn main() {
.arg(&keymap_arg)
.arg(&jobs_arg),
)
+ .subcommand(SubCommand::with_name("configure").about("Edit the starship configuration"))
.subcommand(SubCommand::with_name("bug-report").about(
"Create a pre-populated GitHub issue with information about your configuration",
))
@@ -137,6 +139,7 @@ fn main() {
print::module(module_name, sub_m.clone());
}
}
+ ("configure", Some(_)) => configure::edit_configuration(),
("bug-report", Some(_)) => bug_report::create(),
_ => {}
}