Created
July 6, 2026 05:45
-
-
Save kigster/028224b2041aaafac87d0ef55ba2dbfb to your computer and use it in GitHub Desktop.
gwt() — Bash Function to select a worktree via fzf using the worktree folder and a branch
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
| # vim: ft=bash | |
| gwt() { | |
| local sel dir esc=$'\033' | |
| sel=$(git worktree list --porcelain | awk -v home="$HOME" -v esc="$esc" ' | |
| /^worktree / { wt = $2; sub("^" home, "~", wt) } | |
| /^branch / { sub(/^refs\/heads\//, "", $2) | |
| printf "%s[1;33m%s%s[0m (%s[1;32m%s%s[0m)\n", esc, wt, esc, esc, $2, esc } | |
| /^detached$/ { printf "%s[1;33m%s%s[0m (detached)\n", esc, wt, esc } | |
| ' | fzf --ansi \ | |
| --prompt='worktree > ' --height=40% --reverse --no-multi \ | |
| --color='fg+:bright-white:bold,bg+:238,hl:yellow,hl+:bright-yellow:bold,gutter:-1,pointer:red:bold') || return | |
| dir=${sel%%" ("*} | |
| dir=${dir/#\~/$HOME} | |
| git config --global --add safe.directory "$dir" | |
| cd "$dir" || return | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what it looks like in practice: