fixed home directory expansion regex and made path and dir flags expand home dir
This commit is contained in:
parent
9778cfd7f4
commit
2449af240c
4 changed files with 15 additions and 7 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -13,7 +13,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "config"
|
||||
version = "0.1.2"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"regex",
|
||||
"toml",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "config"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
# config
|
||||
|
||||
`config` is a configuration manager written in Rust.
|
||||
|
13
src/main.rs
13
src/main.rs
|
@ -18,6 +18,8 @@ mod error;
|
|||
|
||||
fn main() -> Result<(), Box<dyn Error>>{
|
||||
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");
|
||||
if !config_path.exists() {
|
||||
|
@ -94,8 +96,9 @@ fn main() -> Result<(), Box<dyn Error>>{
|
|||
if file_path.is_dir() {
|
||||
path = true;
|
||||
} else {
|
||||
let parent = file_path.parent().unwrap();
|
||||
println!("{}", parent.to_str().unwrap());
|
||||
let i_parent = file_path.parent().unwrap().to_str().unwrap();
|
||||
let parent = home_regex.replace(i_parent, home_dir);
|
||||
println!("{}", parent);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +106,8 @@ fn main() -> Result<(), Box<dyn Error>>{
|
|||
if prop_path.is_none() {
|
||||
error::no_property(entry, "path");
|
||||
}
|
||||
let file_path = prop_path.unwrap().as_str().unwrap();
|
||||
let i_file_path = prop_path.unwrap().as_str().unwrap();
|
||||
let file_path = home_regex.replace(i_file_path, home_dir);
|
||||
println!("{}", file_path);
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -118,8 +122,7 @@ fn main() -> Result<(), Box<dyn Error>>{
|
|||
} else {
|
||||
raw_command = prop_command.unwrap().as_str().unwrap().to_string();
|
||||
}
|
||||
let regex = Regex::new("[^~]~")?;
|
||||
let expansion = regex.replace(raw_command.as_str(), home_dir);
|
||||
let expansion = home_regex.replace(raw_command.as_str(), home_dir);
|
||||
let mut parts = expansion.split_whitespace();
|
||||
let command = parts.next().unwrap();
|
||||
|
||||
|
|
Loading…
Reference in a new issue