From f37a10130e48143f406a120d529fa8bd337c2bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Fri, 31 Jul 2026 09:23:33 +0200 Subject: [PATCH] Let worktree picker return to main checkout * Add the current repo's main checkout as the first wt option when run from a linked worktree. * Keep listing worktrees from anywhere without scanning all of ~/Code, so the picker stays fast. --- modules/fish.nix | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/modules/fish.nix b/modules/fish.nix index 61b292a..ab959d1 100644 --- a/modules/fish.nix +++ b/modules/fish.nix @@ -10,23 +10,46 @@ shellAliases.less = "less -R"; functions.wt = '' - set -l root "$HOME/Code/worktrees" + set -l code "$HOME/Code" + set -l root "$code/worktrees" + set -l entries - if not test -d "$root" - echo "No worktrees in $root" >&2 + set -l common_dir (git rev-parse --path-format=absolute --git-common-dir 2>/dev/null) + if test $status -eq 0 + set -l main_root (dirname "$common_dir") + set -l repo (basename "$main_root") + set -l main_checkout (string replace -- "$code/" "" "$main_root") + + if string match --quiet "$root/$repo/*" (pwd); and test "$main_checkout" != "$main_root" + set entries $entries "$main_checkout" + end + + end + + if test -d "$root" + for worktree in (fd --base-directory "$root" --max-depth 2 --min-depth 2 --type directory .) + if not contains -- "$worktree" $entries + set entries $entries "$worktree" + end + end + end + + if test (count $entries) -eq 0 + echo "No worktrees or checkouts in $code" >&2 return 1 end - set -l selected ( - fd --base-directory "$root" --max-depth 2 --min-depth 2 --type directory . \ - | fzf - ) + set -l selected (printf "%s\n" $entries | fzf --no-sort) if test -z "$selected" return end - cd "$root/$selected" + if test -d "$code/$selected" + cd "$code/$selected" + else + cd "$root/$selected" + end ''; functions.wtc = '' -- 2.51.2