sharkdp/bat · error

Could not get home directory

Error message

Could not get home directory

What it means

Error "Could not get home directory" thrown in sharkdp/bat.

Source

Thrown at src/theme.rs:293

}

#[cfg(not(target_os = "macos"))]
fn color_scheme_from_system() -> Option<ColorScheme> {
    crate::bat_warning!(
        "Theme 'auto:system' is only supported on macOS, \
        using default."
    );
    None
}

#[cfg(target_os = "macos")]
fn color_scheme_from_system() -> Option<ColorScheme> {
    const PREFERENCES_FILE: &str = "Library/Preferences/.GlobalPreferences.plist";
    const STYLE_KEY: &str = "AppleInterfaceStyle";

    let preferences_file = std::env::home_dir()
        .map(|home| home.join(PREFERENCES_FILE))
        .expect("Could not get home directory");

    match plist::Value::from_file(preferences_file).map(|file| file.into_dictionary()) {
        Ok(Some(preferences)) => match preferences.get(STYLE_KEY).and_then(|val| val.as_string()) {
            Some("Dark") => Some(ColorScheme::Dark),
            // If the key does not exist, then light theme is currently in use.
            Some(_) | None => Some(ColorScheme::Light),
        },
        // Unreachable, in theory. All macOS users have a home directory and preferences file setup.
        Ok(None) | Err(_) => None,
    }
}

#[cfg(test)]
impl ColorSchemeDetector for Option<ColorScheme> {
    fn should_detect(&self) -> bool {
        true
    }

View on GitHub (pinned to b671e53c2c)

When it happens

Trigger: Thrown at src/theme.rs:293 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sharkdp/bat@b671e53c2c (2026-08-16). Data as JSON: /api/errors/0c6e7bf273fcf2d4. Report an issue: GitHub.