Commit 580d5bba684f

Vincent Demeester <vincent@sbr.pm>
2026-01-27 16:27:53
feat(lazyworktree): human-readable aliases with org picker
- wt_<repo> for direct jump (e.g., wt_pipeline, wt_plumbing) - wt_<org> for fzf picker (e.g., wt_tekton shows all tektoncd repos) - Collision detection: if same repo name in multiple orgs, use wt_<org>_<repo> - Updated prefixes: tekton, osp, gh, gl Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2028c95
Changed files (2)
home/common/dev/lazyworktree.nix
@@ -73,12 +73,14 @@
     };
 
     # Auto-discover repos from these directories
-    # Creates wt<prefix><repo> aliases (e.g., wttpi for tektoncd/pipeline)
+    # Creates:
+    #   wt_<repo>     → jump to repo (e.g., wt_pipeline)
+    #   wt_<prefix>   → fzf picker for org (e.g., wt_tekton)
     discoverDirs = {
-      t = "${config.home.homeDirectory}/src/tektoncd";
-      o = "${config.home.homeDirectory}/src/osp";
-      g = "${config.home.homeDirectory}/src/github.com";
-      l = "${config.home.homeDirectory}/src/gitlab.com";
+      tekton = "${config.home.homeDirectory}/src/tektoncd";
+      osp = "${config.home.homeDirectory}/src/osp";
+      gh = "${config.home.homeDirectory}/src/github.com";
+      gl = "${config.home.homeDirectory}/src/gitlab.com";
     };
   };
 }
home/modules/lazyworktree.nix
@@ -118,29 +118,23 @@ in
         );
 
         # Dynamic aliases: auto-discover repos from source directories
-        # Creates wt<prefix><repo> aliases for each repo found
-        discoverDirsArray = lib.concatStringsSep "\n" (
-          lib.mapAttrsToList (prefix: dir: ''
-            "${dir}:${prefix}"
-          '') cfg.discoverDirs
-        );
-
         dynamicAliasesSetup =
           if cfg.discoverDirs == { } then
             ""
           else
             ''
               # Auto-discover worktree aliases from source directories
-              # Format: wt<prefix><short> → worktree_jump <path>
-              # Uses first 2 letters, extends if collision detected
+              # Creates:
+              #   wt_<repo>  → jump to specific repo
+              #   wt_<org>   → interactive picker for repos in that org
               _lazyworktree_discover_aliases() {
-                local -A alias_map=()
+                local -A repo_dirs=()  # Track repo names to detect collisions
                 local base_dirs=(
                   ${lib.concatStringsSep "\n    " (
                     lib.mapAttrsToList (prefix: dir: ''"${dir}:${prefix}"'') cfg.discoverDirs
                   )}
                 )
-                local entry base_dir prefix repo_dir repo_name target_dir len short alias_name
+                local entry base_dir prefix repo_dir repo_name target_dir alias_name
 
                 for entry in "''${base_dirs[@]}"; do
                   base_dir="''${entry%%:*}"
@@ -148,6 +142,21 @@ in
 
                   [[ -d "$base_dir" ]] || continue
 
+                  # Create org-level picker: wt_<prefix>
+                  eval "wt_''${prefix}() {
+                    local selection
+                    selection=\$(ls -1 \"$base_dir\" 2>/dev/null | fzf --prompt=\"$base_dir: \")
+                    [[ -n \"\$selection\" ]] || return 1
+                    if [[ -d \"$base_dir/\$selection/main\" ]]; then
+                      worktree_jump \"$base_dir/\$selection/main\" \"\$@\"
+                    elif [[ -d \"$base_dir/\$selection/.git\" ]]; then
+                      worktree_jump \"$base_dir/\$selection\" \"\$@\"
+                    else
+                      echo \"Not a git repo: $base_dir/\$selection\" >&2
+                      return 1
+                    fi
+                  }"
+
                   for repo_dir in "$base_dir"/*/; do
                     [[ -d "$repo_dir" ]] || continue
                     repo_name="$(basename "$repo_dir")"
@@ -162,19 +171,14 @@ in
                       continue
                     fi
 
-                    # Generate short name: start with 2 chars, extend if needed
-                    len=2
-                    while (( len <= ''${#repo_name} )); do
-                      short="''${repo_name:0:$len}"
-                      alias_name="wt''${prefix}''${short}"
-                      # Check if alias already exists or conflicts
-                      if [[ -z "''${alias_map[$alias_name]}" ]] || [[ "''${alias_map[$alias_name]}" == "$target_dir" ]]; then
-                        break
-                      fi
-                      (( len++ ))
-                    done
+                    # Create wt_<reponame> alias
+                    # If collision, prefix with org: wt_<prefix>_<reponame>
+                    alias_name="wt_''${repo_name}"
+                    if [[ -n "''${repo_dirs[$alias_name]}" ]] && [[ "''${repo_dirs[$alias_name]}" != "$target_dir" ]]; then
+                      alias_name="wt_''${prefix}_''${repo_name}"
+                    fi
 
-                    alias_map[$alias_name]="$target_dir"
+                    repo_dirs[$alias_name]="$target_dir"
                     eval "''${alias_name}() { worktree_jump \"$target_dir\" \"\$@\"; }"
                   done
                 done