1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::path::Path;
pub fn get_root() -> anyhow::Result<String> {
let basepath = std::env::var("DOTFILES_ROOT").unwrap_or_else(|_| String::from("."));
let full = std::fs::canonicalize(basepath)?;
Ok(full.to_str().unwrap().to_string())
}
pub fn get_to_make(path: String) -> anyhow::Result<String> {
let home = std::env::var("HOME")?;
if Path::new(&format!("{}/{}", home, path)).exists() {
Ok(Path::new(&path)
.parent()
.unwrap()
.to_str()
.unwrap()
.to_owned())
} else {
Ok(Path::new(&path)
.parent()
.unwrap()
.strip_prefix("/")?
.to_str()
.unwrap()
.to_owned())
}
}