1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-07 01:07:00 +00:00
home-manager/modules/programs/eza.nix
NAHO 5af1b9a0f1
treewide: standardize shell integration options
Standardize all 'programs.<PROGRAM>.enable<SHELL>Integration' options
with the following new functions:

- lib.hm.shell.mkBashIntegrationOption
- lib.hm.shell.mkFishIntegrationOption
- lib.hm.shell.mkIonIntegrationOption
- lib.hm.shell.mkNushellIntegrationOption
- lib.hm.shell.mkZshIntegrationOption

These functions should default to their corresponding global option:

- home.shell.enableBashIntegration
- home.shell.enableFishIntegration
- home.shell.enableIonIntegration
- home.shell.enableNushellIntegration
- home.shell.enableZshIntegration

All these global options default to the
'home.shell.enableShellIntegration' value.

This hierarchy standardizes the shell integration and increases end-user
flexibility.

BREAKING CHANGE: The following inconsistent default values change from
'false' to 'true':

- programs.zellij.enableBashIntegration
- programs.zellij.enableFishIntegration
- programs.zellij.enableZshIntegration

Link: https://github.com/nix-community/home-manager/pull/6358

Co-authored-by: Robert Helgesson <robert@rycee.net>
2025-02-08 22:49:40 +01:00

134 lines
4 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
{
imports = let
msg = ''
'programs.eza.enableAliases' has been deprecated and replaced with integration
options per shell, for example, 'programs.eza.enableBashIntegration'.
Note, the default for these options is 'true' so if you want to enable the
aliases you can simply remove 'programs.eza.enableAliases' from your
configuration.'';
mkRenamed = opt:
mkRenamedOptionModule [ "programs" "exa" opt ] [ "programs" "eza" opt ];
in (map mkRenamed [ "enable" "extraOptions" "icons" "git" ])
++ [ (mkRemovedOptionModule [ "programs" "eza" "enableAliases" ] msg) ];
meta.maintainers = [ maintainers.cafkafk ];
options.programs.eza = {
enable = mkEnableOption "eza, a modern replacement for {command}`ls`";
enableBashIntegration =
lib.hm.shell.mkBashIntegrationOption { inherit config; };
enableFishIntegration =
lib.hm.shell.mkFishIntegrationOption { inherit config; };
enableIonIntegration =
lib.hm.shell.mkIonIntegrationOption { inherit config; };
enableNushellIntegration =
lib.hm.shell.mkNushellIntegrationOption { inherit config; };
enableZshIntegration =
lib.hm.shell.mkZshIntegrationOption { inherit config; };
extraOptions = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "--group-directories-first" "--header" ];
description = ''
Extra command line options passed to eza.
'';
};
icons = mkOption {
type = types.enum [ null true false "auto" "always" "never" ];
default = null;
description = ''
Display icons next to file names ({option}`--icons` argument).
Note, the support for Boolean values is deprecated.
Setting this option to `true` corresponds to `--icons=auto`.
'';
};
colors = mkOption {
type = types.enum [ null "auto" "always" "never" ];
default = null;
description = ''
Use terminal colors in output ({option}`--color` argument).
'';
};
git = mkOption {
type = types.bool;
default = false;
description = ''
List each file's Git status if tracked or ignored ({option}`--git` argument).
'';
};
package = mkPackageOption pkgs "eza" { };
};
config = let
cfg = config.programs.eza;
iconsOption = let
v = if isBool cfg.icons then
(if cfg.icons then "auto" else null)
else
cfg.icons;
in optionals (v != null) [ "--icons" v ];
args = escapeShellArgs (iconsOption
++ optionals (cfg.colors != null) [ "--color" cfg.colors ]
++ optional cfg.git "--git" ++ cfg.extraOptions);
optionsAlias = optionalAttrs (args != "") { eza = "eza ${args}"; };
aliases = builtins.mapAttrs (_name: value: lib.mkDefault value) {
ls = "eza";
ll = "eza -l";
la = "eza -a";
lt = "eza --tree";
lla = "eza -la";
};
in mkIf cfg.enable {
warnings = optional (isBool cfg.icons) ''
Setting programs.eza.icons to a Boolean is deprecated.
Please update your configuration so that
programs.eza.icons = ${if cfg.icons then ''"auto"'' else "null"}'';
home.packages = [ cfg.package ];
programs.bash.shellAliases = optionsAlias
// optionalAttrs cfg.enableBashIntegration aliases;
programs.zsh.shellAliases = optionsAlias
// optionalAttrs cfg.enableZshIntegration aliases;
programs.fish = mkMerge [
(mkIf (!config.programs.fish.preferAbbrs) {
shellAliases = optionsAlias
// optionalAttrs cfg.enableFishIntegration aliases;
})
(mkIf config.programs.fish.preferAbbrs {
shellAliases = optionsAlias;
shellAbbrs = optionalAttrs cfg.enableFishIntegration aliases;
})
];
programs.ion.shellAliases = optionsAlias
// optionalAttrs cfg.enableIonIntegration aliases;
programs.nushell.shellAliases = optionsAlias
// optionalAttrs cfg.enableNushellIntegration aliases;
};
}