Repository: sharkdp/bat
File: src/syntax_mapping.rs (Rust)

Code before:
            "*.scope",
            "*.slice",
            "*.socket",
            "*.swap",
            "*.target",
            "*.timer",
        ] {
            mapping.insert(glob, MappingTarget::MapTo("INI")).unwrap();
        }

        // pacman hooks
        mapping
            .insert("*.hook", MappingTarget::MapTo("INI"))
            .unwrap();

        // global git config files
        // `$XDG_CONFIG_HOME/git`, or `$HOME/.config/git` if `$XDG_CONFIG_HOME` is not set or empty
        // see https://git-scm.com/docs/git-config#FILES
        // we cover both cases regardless of the state of `$XDG_CONFIG_HOME`
        if let Some(xdg_config_home) =
            std::env::var_os("XDG_CONFIG_HOME").and_then(|val| (!val.is_empty()).then(|| val))
        {
            insert_git_config_global(&mut mapping, &xdg_config_home);
        }
        if let Some(default_config_home) =
            std::env::var_os("HOME").map(|home| Path::new(&home).join(".config"))
        {
            insert_git_config_global(&mut mapping, &default_config_home);
        }

        fn insert_git_config_global(mapping: &mut SyntaxMapping, config_home: impl AsRef<Path>) {
            let git_config_path = config_home.as_ref().join("git");

            mapping
                .insert(
                    &git_config_path.join("config").to_string_lossy(),
                    MappingTarget::MapTo("Git Config"),
                )
                .ok();

            mapping
                .insert(
                    &git_config_path.join("ignore").to_string_lossy(),
                    MappingTarget::MapTo("Git Ignore"),
                )
                .ok();

            mapping
                .insert(
                    &git_config_path.join("attributes").to_string_lossy(),
                    MappingTarget::MapTo("Git Attributes"),

Review comment (refactor):
Shouldn't you check `!val.is_empty()` also here? Maybe you can move that check into the helper function?

Code after:
            "*.scope",
            "*.slice",
            "*.socket",
            "*.swap",
            "*.target",
            "*.timer",
        ] {
            mapping.insert(glob, MappingTarget::MapTo("INI")).unwrap();
        }

        // pacman hooks
        mapping
            .insert("*.hook", MappingTarget::MapTo("INI"))
            .unwrap();

        // Global git config files rooted in `$XDG_CONFIG_HOME/git/` or `$HOME/.config/git/`
        // See e.g. https://git-scm.com/docs/git-config#FILES
        if let Some(xdg_config_home) =
            std::env::var_os("XDG_CONFIG_HOME").filter(|val| !val.is_empty())
        {
            insert_git_config_global(&mut mapping, &xdg_config_home);
        }
        if let Some(default_config_home) = std::env::var_os("HOME")
            .filter(|val| !val.is_empty())
            .map(|home| Path::new(&home).join(".config"))
        {
            insert_git_config_global(&mut mapping, &default_config_home);
        }

        fn insert_git_config_global(mapping: &mut SyntaxMapping, config_home: impl AsRef<Path>) {
            let git_config_path = config_home.as_ref().join("git");

            mapping
                .insert(
                    &git_config_path.join("config").to_string_lossy(),
                    MappingTarget::MapTo("Git Config"),
                )
                .ok();

            mapping
                .insert(
                    &git_config_path.join("ignore").to_string_lossy(),
                    MappingTarget::MapTo("Git Ignore"),
                )
                .ok();

            mapping
                .insert(
                    &git_config_path.join("attributes").to_string_lossy(),
                    MappingTarget::MapTo("Git Attributes"),
                )