Init
This commit is contained in:
17
src/helpers/mod.rs
Normal file
17
src/helpers/mod.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub const FILE_EXTENSION: &str = "mg";
|
||||
|
||||
pub(crate) fn expand_tilde(path: PathBuf) -> color_eyre::Result<PathBuf> {
|
||||
if path.starts_with("~") {
|
||||
let Some(home) = dirs::home_dir() else {
|
||||
return Err(color_eyre::eyre::eyre!("No home directory found"));
|
||||
};
|
||||
if path == PathBuf::from("~") {
|
||||
return Ok(home);
|
||||
}
|
||||
let relative = path.strip_prefix("~")?;
|
||||
return Ok(home.join(relative));
|
||||
}
|
||||
Ok(path)
|
||||
}
|
||||
Reference in New Issue
Block a user