diff --git a/homes/me/default.nix b/homes/me/default.nix index 34c608f..6380ca2 100755 --- a/homes/me/default.nix +++ b/homes/me/default.nix @@ -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 ]; }; diff --git a/homes/modules/bat.nix b/homes/modules/bat.nix index fca2231..70268f5 100755 --- a/homes/modules/bat.nix +++ b/homes/modules/bat.nix @@ -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: `.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) + ''; + }; + }; + } diff --git a/homes/modules/fish.nix b/homes/modules/fish.nix index 34a2950..dd14c45 100755 --- a/homes/modules/fish.nix +++ b/homes/modules/fish.nix @@ -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 = {