mirror of
https://github.com/nix-community/home-manager.git
synced 2025-03-31 04:04:32 +00:00
feat(bat): interactive init for batpipe
and batman
let `batpipe` and `batman` set up useful env vars for interactive shell
sessions if declared in `programs.bat.extraPackages`, as demonstrated in
upstream nixpkgs
this commit is adapted from the nixpkgs equivalent as it was seen here:
698214a32b/nixos/modules/programs/bat.nix
This commit is contained in:
parent
171915bfce
commit
810e9c9347
1 changed files with 36 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib) literalExpression mkEnableOption mkOption mkIf types;
|
||||
inherit (builtins) elem;
|
||||
inherit (lib)
|
||||
getExe literalExpression mkEnableOption mkOption mkIf optionalString types;
|
||||
|
||||
cfg = config.programs.bat;
|
||||
|
||||
|
@ -18,6 +20,26 @@ let
|
|||
--${k}
|
||||
'') (attrNames enabledBoolFlags);
|
||||
in keyValuePairs + switches;
|
||||
|
||||
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 {
|
||||
meta.maintainers = with lib.maintainers; [ khaneliman ];
|
||||
|
||||
|
@ -167,6 +189,19 @@ in {
|
|||
run ${lib.getExe cfg.package} cache --build
|
||||
)
|
||||
'';
|
||||
|
||||
programs = {
|
||||
bash =
|
||||
mkIf (!config.programs.fish.enable) { initExtra = shellInit "bash"; };
|
||||
fish = mkIf config.programs.fish.enable {
|
||||
interactiveShellInit = shellInit "fish";
|
||||
};
|
||||
zsh =
|
||||
mkIf (!config.programs.fish.enable && config.programs.zsh.enable) {
|
||||
initExtra = shellInit "zsh";
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue