bat: genericize shell init for bat-extras packages (#504544)

This commit is contained in:
Fernando Rodrigues
2026-04-28 14:12:16 +00:00
committed by GitHub
4 changed files with 58 additions and 39 deletions
+16 -39
View File
@@ -5,9 +5,9 @@
...
}:
let
inherit (builtins) isList elem;
inherit (builtins) isList;
inherit (lib)
getExe
concatMapStrings
literalExpression
maintainers
mapAttrs'
@@ -36,33 +36,6 @@ let
boolToString value
else
toString value;
initScript =
{
program,
shell,
flags ? [ ],
}:
if (shell != "fish") then
''
eval "$(${getExe program} ${toString flags})"
''
else
''
${getExe program} ${toString flags} | source
'';
shellInit =
shell:
optionalString (elem pkgs.bat-extras.batpipe cfg.extraPackages) (initScript {
program = pkgs.bat-extras.batpipe;
inherit shell;
})
+ optionalString (elem pkgs.bat-extras.batman cfg.extraPackages) (initScript {
program = pkgs.bat-extras.batman;
inherit shell;
flags = [ "--export-env" ];
});
in
{
options.programs.bat = {
@@ -112,17 +85,21 @@ in
);
};
programs = {
bash = mkIf (!config.programs.fish.enable) {
interactiveShellInit = shellInit "bash";
programs =
let
shellInit = shell: concatMapStrings (pkg: pkg.shellInit shell) cfg.extraPackages;
in
{
bash = mkIf (!config.programs.fish.enable) {
interactiveShellInit = shellInit "bash";
};
fish = mkIf config.programs.fish.enable {
interactiveShellInit = shellInit "fish";
};
zsh = mkIf (!config.programs.fish.enable && config.programs.zsh.enable) {
interactiveShellInit = shellInit "zsh";
};
};
fish = mkIf config.programs.fish.enable {
interactiveShellInit = shellInit "fish";
};
zsh = mkIf (!config.programs.fish.enable && config.programs.zsh.enable) {
interactiveShellInit = shellInit "zsh";
};
};
};
meta.maintainers = with maintainers; [ sigmasquadron ];
}
@@ -16,12 +16,18 @@ let
"name"
"dependencies"
"meta"
"shellInit"
];
in
{
name,
dependencies,
meta ? { },
# Config for the `shellInit` passthru (a `shell -> string`
# function returning the shell-specific init snippet for the bat-extras
# package). Specified as an attrset with a 'flags' string list argument.
# If null, there is no shell init for the package.
shellInit ? null,
...
}@args:
stdenv.mkDerivation (
@@ -76,6 +82,36 @@ stdenv.mkDerivation (
# We have already patched
dontPatchShebangs = true;
passthru =
let
initScript =
{
program,
shell,
flags ? [ ],
}:
if (shell != "fish") then
''
eval "$(${lib.getExe program} ${toString flags})"
''
else
''
${lib.getExe program} ${toString flags} | source
'';
in
{
shellInit =
shell:
if shellInit == null then
""
else
initScript {
program = finalAttrs.finalPackage;
inherit shell;
flags = shellInit.flags or [ ];
};
};
meta = core.meta // { mainProgram = name; } // meta;
}
)
@@ -7,5 +7,8 @@
buildBatExtrasPkg {
name = "batman";
dependencies = lib.optional stdenv.targetPlatform.isLinux util-linux;
shellInit = {
flags = [ "--export-env" ];
};
meta.description = "Read system manual pages (man) using bat as the manual page formatter";
}
@@ -11,6 +11,9 @@ buildBatExtrasPkg {
less
procps
];
shellInit = {
flags = [ ];
};
patches = [
../patches/batpipe-skip-outdated-test.patch