Commit 3a866655d0b0

Vincent Demeester <vincent@sbr.pm>
2026-02-17 15:32:05
feat(lazyworktree): improved worktree aliases with nested repo support
Added wnix alias for nixpkgs repository. Reorganized discovery prefixes with clearer naming: ws for workspace, wt for tektoncd, wo for osp, wgh for github, wgb for gitlab. Implemented special handling for wgh/wgb to support nested org/repo structure (e.g., wgh_vdemeester_chick-group for github.com/vdemeester/chick-group). Standard prefixes continue to use flat structure for direct subdirectories.
1 parent 5881488
Changed files (2)
home/common/dev/lazyworktree.nix
@@ -70,6 +70,7 @@
     # Explicit aliases for commonly used repositories
     aliases = {
       wh = "${config.home.homeDirectory}/src/home";
+      wnix = "${config.home.homeDirectory}/src/nixpkgs";
     };
 
     # Auto-discover repos from these directories
@@ -77,10 +78,11 @@
     #   wt_<repo>     → jump to repo (e.g., wt_pipeline)
     #   wt_<prefix>   → fzf picker for org (e.g., wt_tekton)
     discoverDirs = {
-      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";
+      ws = "${config.home.homeDirectory}/src";
+      wt = "${config.home.homeDirectory}/src/tektoncd";
+      wo = "${config.home.homeDirectory}/src/osp";
+      wgh = "${config.home.homeDirectory}/src/github.com";
+      wgb = "${config.home.homeDirectory}/src/gitlab.com";
     };
   };
 }
home/modules/lazyworktree.nix
@@ -83,8 +83,9 @@ in
             ''
               # Auto-discover worktree aliases from source directories
               # Creates:
-              #   wt_<repo>  → jump to specific repo
-              #   wt_<org>   → interactive picker for repos in that org
+              #   wt_<repo>       → jump to specific repo (flat structure)
+              #   wgh_<org>_<repo> → jump to github.com/org/repo (nested structure)
+              #   wt_<prefix>     → fzf picker for repos in that directory
               _lazyworktree_discover_aliases() {
                 local -A repo_dirs=()  # Track repo names to detect collisions
                 local base_dirs=(
@@ -92,7 +93,7 @@ in
                     lib.mapAttrsToList (prefix: dir: ''"${dir}:${prefix}"'') cfg.discoverDirs
                   )}
                 )
-                local entry base_dir prefix repo_dir repo_name target_dir alias_name
+                local entry base_dir prefix repo_dir repo_name target_dir alias_name org_name
 
                 for entry in "''${base_dirs[@]}"; do
                   base_dir="''${entry%%:*}"
@@ -100,41 +101,72 @@ 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/.git\" ]]; then
+                  # Special handling for wgh/wgb: nested org/repo structure
+                  if [[ "$prefix" == "wgh" ]] || [[ "$prefix" == "wgb" ]]; then
+                    # Create top-level picker: wgh_ → fzf for all repos
+                    eval "''${prefix}_() {
+                      local selection org_dir
+                      selection=\$(find \"$base_dir\" -maxdepth 2 -name .git -type d 2>/dev/null | sed 's|/.git$||' | sed \"s|^$base_dir/||\" | fzf --prompt=\"$base_dir: \")
+                      [[ -n \"\$selection\" ]] || return 1
                       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")"
-                    target_dir=""
+                    # Scan org/repo structure
+                    for org_dir in "$base_dir"/*/; do
+                      [[ -d "$org_dir" ]] || continue
+                      org_name="$(basename "$org_dir")"
+                      
+                      for repo_dir in "$org_dir"/*/; do
+                        [[ -d "$repo_dir" ]] || continue
+                        [[ -d "$repo_dir/.git" ]] || continue
+                        
+                        repo_name="$(basename "$repo_dir")"
+                        target_dir="$repo_dir"
+                        
+                        # Create wgh_<org>_<repo> alias
+                        alias_name="''${prefix}_''${org_name}_''${repo_name}"
+                        repo_dirs[$alias_name]="$target_dir"
+                        eval "''${alias_name}() { worktree_jump \"$target_dir\" \"\$@\"; }"
+                      done
+                    done
+                  else
+                    # Standard flat structure handling
+                    # Create org-level picker: wt_<prefix>
+                    eval "''${prefix}_() {
+                      local selection
+                      selection=\$(ls -1 \"$base_dir\" 2>/dev/null | fzf --prompt=\"$base_dir: \")
+                      [[ -n \"\$selection\" ]] || return 1
+                      if [[ -d \"$base_dir/\$selection/.git\" ]]; then
+                        worktree_jump \"$base_dir/\$selection\" \"\$@\"
+                      else
+                        echo \"Not a git repo: $base_dir/\$selection\" >&2
+                        return 1
+                      fi
+                    }"
 
-                    # Determine target (repo with .git)
-                    if [[ -d "$repo_dir/.git" ]]; then
-                      target_dir="$repo_dir"
-                    else
-                      continue
-                    fi
+                    for repo_dir in "$base_dir"/*/; do
+                      [[ -d "$repo_dir" ]] || continue
+                      repo_name="$(basename "$repo_dir")"
+                      target_dir=""
 
-                    # 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
+                      # Determine target (repo with .git)
+                      if [[ -d "$repo_dir/.git" ]]; then
+                        target_dir="$repo_dir"
+                      else
+                        continue
+                      fi
 
-                    repo_dirs[$alias_name]="$target_dir"
-                    eval "''${alias_name}() { worktree_jump \"$target_dir\" \"\$@\"; }"
-                  done
+                      # Create wt_<reponame> alias
+                      # If collision, prefix with org: wt_<prefix>_<reponame>
+                      alias_name="''${prefix}_''${repo_name}"
+                      if [[ -n "''${repo_dirs[$alias_name]}" ]] && [[ "''${repo_dirs[$alias_name]}" != "$target_dir" ]]; then
+                        alias_name="''${prefix}_''${repo_name}"
+                      fi
+
+                      repo_dirs[$alias_name]="$target_dir"
+                      eval "''${alias_name}() { worktree_jump \"$target_dir\" \"\$@\"; }"
+                    done
+                  fi
                 done
               }
               _lazyworktree_discover_aliases >/dev/null 2>&1