dircolors: respect preferXdgDirectories if set

This commit is contained in:
Shaw Vrana 2024-07-10 16:29:41 -07:00
parent 635563f245
commit 511fbb2dd0

View file

@ -69,7 +69,8 @@ in {
};
};
config = mkIf cfg.enable {
config = mkIf cfg.enable (mkMerge [
{
# Add default settings from `dircolors --print-database`.
programs.dircolors.settings = {
RESET = mkDefault "0";
@ -202,7 +203,9 @@ in {
".spx" = mkDefault "00;36";
".xspf" = mkDefault "00;36";
};
}
(mkIf (!config.home.preferXdgDirectories) {
home.file.".dir_colors".text = concatStringsSep "\n" ([ ]
++ mapAttrsToList formatLine cfg.settings ++ [ "" ]
++ optional (cfg.extraConfig != "") cfg.extraConfig);
@ -219,5 +222,24 @@ in {
programs.zsh.initExtraBeforeCompInit = mkIf cfg.enableZshIntegration ''
eval $(${pkgs.coreutils}/bin/dircolors -b ~/.dir_colors)
'';
};
})
(mkIf config.home.preferXdgDirectories {
xdg.configFile.dir_colors.text = concatStringsSep "\n" ([ ]
++ mapAttrsToList formatLine cfg.settings ++ [ "" ]
++ optional (cfg.extraConfig != "") cfg.extraConfig);
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
eval $(${pkgs.coreutils}/bin/dircolors -b ${config.xdg.configHome}/dir_colors)
'';
programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
eval (${pkgs.coreutils}/bin/dircolors -c ${config.xdg.configHome}/dir_colors)
'';
# Set `LS_COLORS` before Oh My Zsh and `initExtra`.
programs.zsh.initExtraBeforeCompInit = mkIf cfg.enableZshIntegration ''
eval $(${pkgs.coreutils}/bin/dircolors -b ${config.xdg.configHome}/dir_colors)
'';
})
]);
}