Expand tilde sign in custom git repositories

This commit is contained in:
Roey Darwish Dror
2018-06-11 13:56:57 +03:00
parent 03f035cc83
commit 9949d0c38d
4 changed files with 19 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
use directories;
use failure;
use shellexpand;
use std::collections::BTreeMap;
use std::fs;
use toml;
@@ -18,7 +19,15 @@ impl Config {
return Ok(Default::default());
}
Ok(toml::from_str(&fs::read_to_string(config_path)?)?)
let mut result: Self = toml::from_str(&fs::read_to_string(config_path)?)?;
if let Some(ref mut paths) = &mut result.git_repos {
for path in paths.iter_mut() {
*path = shellexpand::tilde::<&str>(&path.as_ref()).into_owned();
}
}
Ok(result)
}
pub fn commands(&self) -> &Option<BTreeMap<String, String>> {

View File

@@ -8,6 +8,7 @@ extern crate toml;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate shellexpand;
mod config;
mod git;