let # Module Meta Configuration setShellAliases = true; supportBash = true; supportZsh = true; supportFish = true; in { osConfig, config, pkgs, lib, username, ... }: let inherit (builtins) elemAt ; inherit (lib) flip mkIf optional splitString ; cfg = config.programs.bat; # NOTE: `.pname` can be used instead of `.meta.mainProgram` # NOTE: but then `pkgs.bash` would return `"bash-interactive"` which is annoying... shellPkg = osConfig.users.users.${username}.shell; shell = shellPkg.meta.mainProgram; pager = cfg.config.pager |> splitString " " |> flip elemAt 0; in { programs.bat = { enable = true; config = { # WARNING: pager must be set for this module to function # NOTE: not sure whether to use ov/moor/viddy as my pager? pager = "less -FR"; # theme = "Dracula"; }; }; home = { shellAliases = mkIf setShellAliases { bat = "prettybat"; cat = "prettybat"; diff = "batdiff"; brg = "batgrep"; man = "batman"; # watch = "batwatch"; # NOTE: using viddy instead atm }; sessionVariables = { PAGER = pager; # REF: https://github.com/eth-p/bat-extras/blob/master/doc/batpipe.md BATPIPE_ENABLE_COLOR = "true"; BATPIPE_INSIDE_LESS = "true"; BATPIPE_TERM_WIDTH = "-"; # hyphone -> auto detect }; packages = with pkgs.bat-extras; [ batdiff batgrep batman batpipe batwatch prettybat ] ++ (with pkgs; [ bat entr # required by pkgs.bat-extras.batwatch ripgrep # required by pkgs.bat-extras.batgrep delta # required by pkgs.bat-extras.batdiff ]) ++ optional (pkgs?${pager}) pkgs.${pager}; }; # Configure the user's shell to source batpipe # WARNING: only currently supports bash, zsh, & fish programs = { bash = mkIf (supportBash || shell == "bash") { initExtra = '' eval "$(batpipe)" ''; }; zsh = mkIf (supportZsh || shell == "zsh") { initContent = '' eval "$(batpipe)" ''; }; fish = mkIf (supportFish || shell == "fish") { interactiveShellInit = '' eval (batpipe) ''; }; }; }