diff --git a/.gitignore b/.gitignore index ea8c4bf..06aba01 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +Cargo.lock /target diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 93ba5ba..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,58 +0,0 @@ -# This file is automatically @generated by Cargo. -# 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.2.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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] diff --git a/Cargo.toml b/Cargo.toml index 68190b5..b35027c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ 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" [profile.release] diff --git a/README.md b/README.md index 33aa0db..e7cd906 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # config -`config` is a configuration manager written in Rust. +`config` is a command line configuration manager written in Rust. diff --git a/src/main.rs b/src/main.rs index 6cf816f..acfda62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,6 @@ use std::{ } }; -use regex::Regex; use toml::{ Value, value::Map @@ -19,7 +18,6 @@ mod error; fn main() -> Result<(), Box>{ let home_dir = var("HOME").unwrap(); - let home_regex = Regex::new("^~")?; let mut config_path = PathBuf::from(&home_dir); config_path.push(".config/config.toml"); @@ -101,14 +99,14 @@ fn main() -> Result<(), Box>{ error::no_property(&fullname, "path"); } let raw_path = prop_path.unwrap().as_str().unwrap(); - let expanded = home_regex.replace(raw_path, &home_dir); + let expanded = if raw_path.starts_with("~") { raw_path.replacen("~", &home_dir, 1) } else { raw_path.to_string() }; let file_path = PathBuf::from(expanded.to_string()); if file_path.is_dir() { println!("{}", expanded); return Ok(()); } else { let i_parent = file_path.parent().unwrap().to_str().unwrap(); - let parent = home_regex.replace(i_parent, home_dir); + let parent = if i_parent.starts_with("~") { i_parent.replacen("~", &home_dir, 1) } else { i_parent.to_string() }; println!("{}", parent); return Ok(()); } @@ -118,7 +116,7 @@ fn main() -> Result<(), Box>{ error::no_property(&fullname, "path"); } let i_file_path = prop_path.unwrap().as_str().unwrap(); - let file_path = home_regex.replace(i_file_path, home_dir); + let file_path = if i_file_path.starts_with("~") { i_file_path.replace("~", &home_dir) } else { i_file_path.to_string() }; println!("{}", file_path); return Ok(()); } @@ -133,7 +131,7 @@ fn main() -> Result<(), Box>{ } else { raw_command = prop_command.unwrap().as_str().unwrap().to_string(); } - let expansion = home_regex.replace(raw_command.as_str(), home_dir); + let expansion = if raw_command.starts_with("~") { raw_command.replace("~", &home_dir) } else { raw_command.to_string() }; let mut parts = expansion.split_whitespace(); let command = parts.next().unwrap();