feat(notcore): add shared types, config, paths, error crate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Joseph O'Brien
2026-03-31 17:17:35 -04:00
parent 84629d8be7
commit 6b0bd3beb6
15 changed files with 387 additions and 18 deletions

View File

@@ -0,0 +1,42 @@
use std::path::PathBuf;
use crate::NotfilesError;
pub fn expand_tilde(path: &str) -> Result<PathBuf, NotfilesError> {
if path == "~" {
return dirs::home_dir()
.ok_or_else(|| NotfilesError::Path("cannot determine home directory".into()));
}
if let Some(rest) = path.strip_prefix("~/") {
let home = dirs::home_dir()
.ok_or_else(|| NotfilesError::Path("cannot determine home directory".into()))?;
return Ok(home.join(rest));
}
Ok(PathBuf::from(path))
}
pub fn dotfiles_dir() -> Option<PathBuf> {
dirs::home_dir().map(|h| h.join("dotfiles"))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_expand_tilde_home() {
let home = dirs::home_dir().unwrap();
assert_eq!(expand_tilde("~").unwrap(), home);
}
#[test]
fn test_expand_tilde_subpath() {
let home = dirs::home_dir().unwrap();
assert_eq!(expand_tilde("~/foo/bar").unwrap(), home.join("foo/bar"));
}
#[test]
fn test_expand_tilde_absolute() {
assert_eq!(expand_tilde("/usr/bin").unwrap(), PathBuf::from("/usr/bin"));
}
}