From 810e9c9347699f0ab5db49c9f64d2d3a1bf53e79 Mon Sep 17 00:00:00 2001 From: Minh Tran <33189614+minhtrancccp@users.noreply.github.com> Date: Thu, 27 Mar 2025 23:07:49 +0700 Subject: [PATCH] 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: https://github.com/NixOS/nixpkgs/blob/698214a32beb4f4c8e3942372c694f40848b360d/nixos/modules/programs/bat.nix --- modules/programs/bat.nix | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/programs/bat.nix b/modules/programs/bat.nix index fce1f5e63..295d0fcf7 100644 --- a/modules/programs/bat.nix +++ b/modules/programs/bat.nix @@ -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"; + }; + }; + } ]); }