Created
August 19, 2025 14:56
-
-
Save withakay/dec184e9a0a5111b929e6ad8f0399d04 to your computer and use it in GitHub Desktop.
Switch git work trees interactively with fzf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # include this in your .bash_profile or .zshrc or similar | |
| # Note: you can't put this in script and call it as `cd` will only affect | |
| # the subshell the script runs in | |
| function wtcd () { | |
| local dir | |
| dir=$(git wtl --porcelain | grep "^worktree" | awk '{print $2}'| fzf \ | |
| --height=40% \ | |
| --layout=reverse \ | |
| --border \ | |
| --prompt="Select worktree: " \ | |
| --preview="echo {} | awk '{print \$1}' | xargs ls -la 2>/dev/null | head -20" \ | |
| --preview-window=right:50%:wrap) && cd "$dir" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment