From 0f13940c13f28255941bcba240d1cc4c538dc108 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Tue, 3 Feb 2026 11:51:59 -0800 Subject: fix: use directories crate for home dir resolution (#3125) Previously, home_dir() read $HOME directly and panicked if it wasn't set. This could happen in environments like `nix develop -i` which strip the environment. The directories crate (already a dependency) falls back to getpwuid_r when $HOME is not set, resolving the home directory from /etc/passwd. Fixes #3123 ## Checks - [ ] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [ ] I have checked that there are no existing pull requests for the same thing --- crates/atuin-common/src/utils.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/atuin-common/src/utils.rs b/crates/atuin-common/src/utils.rs index 9f7d99c6..bb291ebf 100644 --- a/crates/atuin-common/src/utils.rs +++ b/crates/atuin-common/src/utils.rs @@ -65,16 +65,10 @@ pub fn in_git_repo(path: &str) -> Option { // I don't want to use ProjectDirs, it puts config in awkward places on // mac. Data too. Seems to be more intended for GUI apps. -#[cfg(not(target_os = "windows"))] pub fn home_dir() -> PathBuf { - let home = std::env::var("HOME").expect("$HOME not found"); - PathBuf::from(home) -} - -#[cfg(target_os = "windows")] -pub fn home_dir() -> PathBuf { - let home = std::env::var("USERPROFILE").expect("%userprofile% not found"); - PathBuf::from(home) + directories::BaseDirs::new() + .map(|d| d.home_dir().to_path_buf()) + .expect("could not determine home directory") } pub fn config_dir() -> PathBuf { -- cgit v1.3.1