added command home expansion and default 'shell' value option

This commit is contained in:
Valerie Wolfe 2022-06-27 21:46:17 -04:00
parent c78bbf21c3
commit 594345785b
3 changed files with 43 additions and 4 deletions

33
Cargo.lock generated
View file

@ -2,13 +2,46 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 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]] [[package]]
name = "config" name = "config"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"regex",
"toml", "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]] [[package]]
name = "serde" name = "serde"
version = "1.0.137" version = "1.0.137"

View file

@ -1,9 +1,10 @@
[package] [package]
name = "config" name = "config"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
regex = "1.5.6"
toml = "0.5.9" toml = "0.5.9"

View file

@ -11,11 +11,12 @@ use std::{
} }
}; };
use regex::Regex;
use toml::Value; use toml::Value;
mod error; mod error;
pub const VERSION: &str = "0.1.0"; pub const VERSION: &str = "0.1.1";
fn main() -> Result<(), Box<dyn Error>>{ fn main() -> Result<(), Box<dyn Error>>{
let home_dir = var("HOME").unwrap(); let home_dir = var("HOME").unwrap();
@ -32,6 +33,8 @@ fn main() -> Result<(), Box<dyn Error>>{
let i_editor = var("EDITOR"); let i_editor = var("EDITOR");
let editor: Option<String> = if i_editor.is_ok() { Some(i_editor.unwrap()) } else { None }; let editor: Option<String> = 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<String> = args().skip(1).collect(); let args: Vec<String> = args().skip(1).collect();
let mut dir = false; let mut dir = false;
let mut list = false; let mut list = false;
@ -117,7 +120,9 @@ fn main() -> Result<(), Box<dyn Error>>{
} else { } else {
raw_command = prop_command.unwrap().as_str().unwrap().to_string(); 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 command = parts.next().unwrap();
let prop_shell = section.get("shell"); let prop_shell = section.get("shell");
@ -125,7 +130,7 @@ fn main() -> Result<(), Box<dyn Error>>{
if prop_shell.is_some() { if prop_shell.is_some() {
shell = prop_shell.unwrap().as_bool().unwrap(); shell = prop_shell.unwrap().as_bool().unwrap();
} else { } else {
shell = false; shell = shell_default;
} }
let mut process = Command::new(command); let mut process = Command::new(command);