Fix fzf recipe to handle header row and current worktree marker#118
Fix fzf recipe to handle header row and current worktree marker#118k1LoW merged 1 commit intok1LoW:mainfrom
Conversation
- Add --header-lines=1 so the table header is visible but not selectable - Fix awk to extract the path correctly when the current worktree (prefixed with *) is selected Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Updates the README’s fzf “interactive worktree selection” recipes to treat the first row as a non-selectable header and to correctly extract the worktree path when selecting the current worktree (marked with *).
Changes:
- Add
fzf --header-lines=1to keep the header visible but not selectable. - Adjust
awkto print the correct field when the selected row starts with the current-worktree marker*.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| ``` console | ||
| $ cd $(git-wt | fzf | awk '{print $1}') | ||
| $ cd $(git-wt | fzf --header-lines=1 | awk '{if ($1 == "*") print $2; else print $1}') |
There was a problem hiding this comment.
The command substitution can expand to an empty string when the user cancels fzf (Esc/Ctrl-C). In that case cd is invoked with no argument and will take the user to $HOME, so this still doesn’t address the issue described in #117 even though the PR claims to fix it. Capture the selection into a variable and only run cd when it’s non-empty (and ideally check fzf’s exit status).
|
|
||
| ``` console | ||
| $ cd $(git-wt | fzf | awk '{print $1}') | ||
| $ cd $(git-wt | fzf --header-lines=1 | awk '{if ($1 == "*") print $2; else print $1}') |
There was a problem hiding this comment.
This bash/zsh one-liner is not safe for worktree paths that contain spaces (command substitution + awk + unquoted cd will word-split the path). Consider quoting the resulting path and/or using a selection format that’s unambiguous for paths with spaces.
|
|
||
| ``` console | ||
| $ cd (git-wt | fzf | awk '{print $1}') | ||
| $ cd (git-wt | fzf --header-lines=1 | awk '{if ($1 == "*") print $2; else print $1}') |
There was a problem hiding this comment.
Same as the bash/zsh recipe: if fzf is canceled, the substitution becomes empty and cd with no argument will switch to the home directory. Update this recipe to guard against an empty selection (and/or non-zero fzf exit status) before calling cd to truly resolve #117.
|
|
||
| ``` console | ||
| $ cd (git-wt | fzf | awk '{print $1}') | ||
| $ cd (git-wt | fzf --header-lines=1 | awk '{if ($1 == "*") print $2; else print $1}') |
There was a problem hiding this comment.
In fish, command substitution splits on whitespace, so a selected worktree path containing spaces would be split into multiple arguments and cd will fail. Prefer capturing the selection into a variable and then cd -- "$var" (or otherwise preserving spaces) to make the recipe robust.
| $ cd (git-wt | fzf --header-lines=1 | awk '{if ($1 == "*") print $2; else print $1}') | |
| $ set -l wt_dir (git-wt | fzf --header-lines=1 | awk '{if ($1 == "*") print $2; else print $1}') | |
| $ cd -- "$wt_dir" |
|
Thank you for the good improvement!! |
|
Great recipe! I've created #122 as a place to collect community recipes like this — feel free to post it there. |
Done 👍🏻 What do you think about the feature(s) request (custom output separator and/or pre-defined output formats, custom fields order, disable header row)? Thanks. |
|
I went ahead and created #123. Thanks. |


Summary
--header-lines=1so the table header is visible but not selectable in fzf*) is selectedFixes #117
Test plan
cd $(git-wt | fzf --header-lines=1 | awk '{if ($1 == "*") print $2; else print $1}')in bash/zsh*) and verify it cds to the correct path🤖 Generated with Claude Code