configure bat

This commit is contained in:
do butterflies cry? 2026-03-22 11:47:57 +10:00
parent f9f0e9b9c7
commit 64325631a6
Signed by: cry
GPG key ID: F68745A836CA0412
3 changed files with 114 additions and 34 deletions

View file

@ -31,8 +31,10 @@
ntv = "nix-search-tv";
rebuild = "nh os switch ~/flake";
trybuild = "nh os test ~/flake";
brip = "batgrep"; # bat + ripgrep
man = "batman"; # bat + man
# shell utilities
rgf = "rg --files | rg";
watch = "viddy";
};
pointerCursor = {
@ -45,14 +47,13 @@
packages = with pkgs; [
# for services.gnome-keyring
pkgs.gcr # provides org.gnome.keyring.SystemPrompter
gcr # provides org.gnome.keyring.SystemPrompter
seahorse # gui
krita
krita
tor-browser
fuzzel
speedtest-cli
];
};

View file

@ -1,24 +1,109 @@
{
config,
pkgs,
...
}: {
# like `/bin/cat` but with syntax highlighting
# TODO: change the pager (maybe use Github:sachaos/viddy instead)
programs.bat = {
enable = true;
config = {
pager = "less -FR";
theme = "Dracula";
};
};
let
# Module Meta Configuration
setShellAliases = true;
supportBash = true;
supportZsh = true;
supportFish = true;
in
{
osConfig,
config,
pkgs,
lib,
username,
...
}: let
inherit
(builtins)
elemAt
;
# other commands that make normal utils prettier
home.packages = with pkgs.bat-extras; [
batdiff
batgrep
batman
batwatch
prettybat
];
}
inherit
(lib)
flip
mkIf
optional
splitString
;
cfg = config.programs.bat;
# NOTE: `<derivation>.pname` can be used instead of `<derivation>.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)
'';
};
};
}

View file

@ -1,5 +1,4 @@
{
config,
lib,
pkgs,
...
@ -60,9 +59,6 @@
curl -sL "https://www.gitignore.io/api/$type"
end
# ripgrep on files
function rgf
rg --files | rg $args
end
function decompile
@ -70,8 +66,6 @@
end
set -g fish_greeting (rand_greet)
'';
shellAliases = {