added command home expansion and default 'shell' value option
This commit is contained in:
parent
c78bbf21c3
commit
594345785b
3 changed files with 43 additions and 4 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
11
src/main.rs
11
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<dyn Error>>{
|
||||
let home_dir = var("HOME").unwrap();
|
||||
|
@ -32,6 +33,8 @@ fn main() -> Result<(), Box<dyn Error>>{
|
|||
let i_editor = var("EDITOR");
|
||||
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 mut dir = false;
|
||||
let mut list = false;
|
||||
|
@ -117,7 +120,9 @@ fn main() -> Result<(), Box<dyn Error>>{
|
|||
} 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<dyn Error>>{
|
|||
if prop_shell.is_some() {
|
||||
shell = prop_shell.unwrap().as_bool().unwrap();
|
||||
} else {
|
||||
shell = false;
|
||||
shell = shell_default;
|
||||
}
|
||||
|
||||
let mut process = Command::new(command);
|
||||
|
|
Loading…
Reference in a new issue