summaryrefslogtreecommitdiffstats
path: root/src/configure.rs
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/configure.rs
parentc82aeb70db7e8ad3d1ca984eea52c76de35daf39 (diff)
feat: Implement `starship configure` command (#751)
Diffstat (limited to 'src/configure.rs')
-rw-r--r--src/configure.rs37
1 files changed, 37 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(),
+ }
+}