diff options
| author | Ellie Huxtable <ellie@atuin.sh> | 2026-02-03 11:51:59 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-03 11:51:59 -0800 |
| commit | 0f13940c13f28255941bcba240d1cc4c538dc108 (patch) | |
| tree | f9011f1b76530200c21549b724df3b3ebe4ad08d /crates/atuin-common/src/utils.rs | |
| parent | fix: halt sync loop if server returns an empty page (#3122) (diff) | |
| download | atuin-0f13940c13f28255941bcba240d1cc4c538dc108.zip | |
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
<!-- Thank you for making a PR! Bug fixes are always welcome, but if
you're adding a new feature or changing an existing one, we'd really
appreciate if you open an issue, post on the forum, or drop in on
Discord -->
## 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
Diffstat (limited to 'crates/atuin-common/src/utils.rs')
| -rw-r--r-- | crates/atuin-common/src/utils.rs | 12 |
1 files 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<PathBuf> { // 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 { |
