From 3b5ffc09e74f9c781c9f766efaa484f9242b9ac0 Mon Sep 17 00:00:00 2001 From: Tomas Rivera <137088692+Totorile1@users.noreply.github.com> Date: Sun, 8 Mar 2026 18:41:34 +0100 Subject: [PATCH] added custom man script --- hosts/laptop/configuration.nix | 1 + hosts/laptop/home.nix | 1 + modules/home-manager/zsh.nix | 1 + modules/scripts/man.nix | 43 ++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 modules/scripts/man.nix diff --git a/hosts/laptop/configuration.nix b/hosts/laptop/configuration.nix index 2d09193..71d952a 100755 --- a/hosts/laptop/configuration.nix +++ b/hosts/laptop/configuration.nix @@ -16,6 +16,7 @@ ]; +documentation.man.generateCaches = true; # used for the man script # grub theme boot.loader.grub = { diff --git a/hosts/laptop/home.nix b/hosts/laptop/home.nix index 647b3e5..4f9f026 100755 --- a/hosts/laptop/home.nix +++ b/hosts/laptop/home.nix @@ -73,6 +73,7 @@ home.packages = [ (pkgs.callPackage ../../modules/scripts/performance-mode.nix {}) (pkgs.callPackage ../../modules/scripts/btm.nix {}) (pkgs.callPackage ../../modules/scripts/manix.nix {}) +(pkgs.callPackage ../../modules/scripts/man.nix {}) #pkgs pkgs.gruvbox-gtk-theme # # Adds the 'hello' command to your environment. It prints a friendly diff --git a/modules/home-manager/zsh.nix b/modules/home-manager/zsh.nix index 98b8217..1cfda9d 100644 --- a/modules/home-manager/zsh.nix +++ b/modules/home-manager/zsh.nix @@ -27,6 +27,7 @@ custom-cat() { pomodoro = "custom-tomato"; librewolf = "kitty --class \"custom-librewolfprofiles\" --name \"Select LibreWolf profile\" --hold custom-librewolfprofiles"; manix = "custom-manix"; + man = "custom-man"; }; }; } diff --git a/modules/scripts/man.nix b/modules/scripts/man.nix new file mode 100644 index 0000000..4ead15f --- /dev/null +++ b/modules/scripts/man.nix @@ -0,0 +1,43 @@ +{ writeShellApplication, man, ripgrep, fzf, ... }: + +let + cacheTime = "10"; +in + +writeShellApplication { + name = "custom-man"; + runtimeInputs = [ + man + ripgrep + fzf + ]; + text = '' +CACHE_DIR="''${XDG_CACHE_HOME:-$HOME/.cache}" +CACHE_FILE="$CACHE_DIR/custom-man-options.txt" +mkdir -p "$CACHE_DIR" + +REGENERATE=0 + +# check if -r flag was passed +if [ "''${1:-}" = "-r" ]; then + REGENERATE=1 +fi + + +# regenerate if file does not exist or is older than cacheTime days +if [ ! -f "$CACHE_FILE" ] || [ "$(find "$CACHE_FILE" -mtime +${cacheTime} -print)" ]; then + REGENERATE=1 +fi + +if [ $REGENERATE -eq 1 ]; then + echo "(Re)building custom-manix cache..." + mkdir -p "$(dirname "$CACHE_FILE")" + man -k . > "$CACHE_FILE" +fi + +# read from cache and pipe into fzf +cat "$CACHE_FILE" \ + | fzf --preview "man {1}" \ + | xargs man + ''; +}