Commit 475563f80cd3

Vincent Demeester <vincent@sbr.pm>
2026-02-24 07:02:57
feat: add worktree jump via raffi script filter
Added lazyworktree-raffi script that lists git repos under ~/src/ with 2-hour caching and query filtering. Raffi 'wt' keyword opens lazyworktree in kitty for the selected repository.
1 parent 079fba1
Changed files (3)
home
common
desktop
pkgs
home/common/desktop/sway/rofi.nix
@@ -180,6 +180,13 @@
           args = [ "-j" ];
           icon = "clock";
         }
+        {
+          name = "Worktrees";
+          keyword = "wt";
+          command = "lazyworktree-raffi";
+          icon = "folder";
+          action = "kitty --title Worktrees --directory {value} lazyworktree";
+        }
       ];
     };
   };
pkgs/my/scripts/bin/lazyworktree-raffi
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+# List git repositories under ~/src/ for raffi script filter.
+# Outputs Alfred Script Filter JSON format.
+# Results are cached for 2 hours.
+# Usage: lazyworktree-raffi [query]
+set -euo pipefail
+
+CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/lazyworktree-raffi"
+CACHE_FILE="$CACHE_DIR/repos.json"
+CACHE_MAX_AGE=7200 # 2 hours in seconds
+SRC_DIR="$HOME/src"
+
+mkdir -p "$CACHE_DIR"
+
+# Rebuild cache if missing or older than CACHE_MAX_AGE
+rebuild=0
+if [[ ! -f "$CACHE_FILE" ]]; then
+    rebuild=1
+elif [[ "$(uname)" == "Darwin" ]]; then
+    file_age=$(( $(date +%s) - $(stat -f %m "$CACHE_FILE") ))
+    [[ "$file_age" -gt "$CACHE_MAX_AGE" ]] && rebuild=1
+else
+    file_age=$(( $(date +%s) - $(stat -c %Y "$CACHE_FILE") ))
+    [[ "$file_age" -gt "$CACHE_MAX_AGE" ]] && rebuild=1
+fi
+
+if [[ "$rebuild" -eq 1 ]]; then
+    find "$SRC_DIR" -name .git -type d -not -path '*/worktrees/*' 2>/dev/null \
+        | sed 's|/\.git$||' \
+        | sort \
+        | jq -R --arg src "$SRC_DIR" '{
+            title: (. | ltrimstr($src + "/") ),
+            subtitle: .,
+            arg: .
+        }' \
+        | jq -s '.' \
+        > "$CACHE_FILE"
+fi
+
+query="${*:-}"
+
+if [[ -z "$query" ]]; then
+    jq '{ items: . }' "$CACHE_FILE"
+else
+    jq --arg q "$query" '
+      [ .[] | select(
+          .title | ascii_downcase | contains($q | ascii_downcase)
+      )]
+      | { items: . }
+    ' "$CACHE_FILE"
+fi
pkgs/my/scripts/default.nix
@@ -5,7 +5,7 @@
 
 stdenv.mkDerivation {
   pname = "vde-scripts";
-  version = "0.7";
+  version = "0.8";
 
   src = ./.;