From 4bac34186886f8d484791702f32ec371f8c7a81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20H=C3=B6ner?= Date: Tue, 28 Feb 2023 18:24:36 +0100 Subject: [PATCH] `exa`: add more options (#3505) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * exa: add more options * exa: use `escapeShellArgs` * exa: don't hardcode executable path in aliases Prevents aliases from going stale in open terminals when the system is updated. * exa: use `command` for self-referential alias Otherwise fish complains about the recursive call. Drop the aliases from ion shell since it doesn't implement the POSIX `command` built-in. * exa: re-add ion aliases * exa: drop `command` Fish doesn't complain about recursion if `exa` isn't escaped. --------- Co-authored-by: Naïm Favier --- modules/programs/exa.nix | 57 ++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/modules/programs/exa.nix b/modules/programs/exa.nix index a1b4a2712..897020bbb 100644 --- a/modules/programs/exa.nix +++ b/modules/programs/exa.nix @@ -2,19 +2,7 @@ with lib; -let - - cfg = config.programs.exa; - - aliases = { - ls = "${pkgs.exa}/bin/exa"; - ll = "${pkgs.exa}/bin/exa -l"; - la = "${pkgs.exa}/bin/exa -a"; - lt = "${pkgs.exa}/bin/exa --tree"; - lla = "${pkgs.exa}/bin/exa -la"; - }; - -in { +{ meta.maintainers = [ hm.maintainers.kalhauge ]; options.programs.exa = { @@ -23,10 +11,51 @@ in { enableAliases = mkEnableOption "recommended exa aliases"; + extraOptions = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "--group-directories-first" "--header" ]; + description = '' + Extra command line options passed to exa. + ''; + }; + + icons = mkOption { + type = types.bool; + default = false; + description = '' + Display icons next to file names ( argument). + ''; + }; + + git = mkOption { + type = types.bool; + default = false; + description = '' + List each file's Git status if tracked or ignored ( argument). + ''; + }; + package = mkPackageOption pkgs "exa" { }; }; - config = mkIf cfg.enable { + config = let + cfg = config.programs.exa; + + args = escapeShellArgs (optional cfg.icons "--icons" + ++ optional cfg.git "--git" ++ cfg.extraOptions); + + aliases = { + # Use `command` instead of hardcoding the path to exa so that aliases don't + # go stale after a system update. + exa = "exa ${args}"; + ls = "exa"; + ll = "exa -l"; + la = "exa -a"; + lt = "exa --tree"; + lla = "exa -la"; + }; + in mkIf cfg.enable { home.packages = [ cfg.package ]; programs.bash.shellAliases = mkIf cfg.enableAliases aliases;