From 594345785b8229e09b7bfaa41b7d3667e8fb48cc Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 27 Jun 2022 21:46:17 -0400 Subject: [PATCH] added command home expansion and default 'shell' value option --- Cargo.lock | 33 +++++++++++++++++++++++++++++++++ Cargo.toml | 3 ++- src/main.rs | 11 ++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 522f387..fa98656 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,46 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + [[package]] name = "config" version = "0.1.0" dependencies = [ + "regex", "toml", ] +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "regex" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" + [[package]] name = "serde" version = "1.0.137" diff --git a/Cargo.toml b/Cargo.toml index 5d6de47..9549bd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "config" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +regex = "1.5.6" toml = "0.5.9" diff --git a/src/main.rs b/src/main.rs index 624a159..063322c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,11 +11,12 @@ use std::{ } }; +use regex::Regex; use toml::Value; mod error; -pub const VERSION: &str = "0.1.0"; +pub const VERSION: &str = "0.1.1"; fn main() -> Result<(), Box>{ let home_dir = var("HOME").unwrap(); @@ -32,6 +33,8 @@ fn main() -> Result<(), Box>{ let i_editor = var("EDITOR"); let editor: Option = if i_editor.is_ok() { Some(i_editor.unwrap()) } else { None }; + let shell_default = if config.contains_key("shell") { config.get("shell").unwrap().as_bool().unwrap() } else { false }; + let args: Vec = args().skip(1).collect(); let mut dir = false; let mut list = false; @@ -117,7 +120,9 @@ fn main() -> Result<(), Box>{ } else { raw_command = prop_command.unwrap().as_str().unwrap().to_string(); } - let mut parts = raw_command.split_whitespace(); + let regex = Regex::new("[^~]~")?; + let expansion = regex.replace(raw_command.as_str(), home_dir); + let mut parts = expansion.split_whitespace(); let command = parts.next().unwrap(); let prop_shell = section.get("shell"); @@ -125,7 +130,7 @@ fn main() -> Result<(), Box>{ if prop_shell.is_some() { shell = prop_shell.unwrap().as_bool().unwrap(); } else { - shell = false; + shell = shell_default; } let mut process = Command::new(command);