Last active
September 5, 2022 11:19
-
-
Save orip/16965728eb0d10f369b7a158d62dec74 to your computer and use it in GitHub Desktop.
`wt` zsh function to switch between git worktrees using fzf
This file contains 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
wt() { | |
if [ "$#" -eq 0 ]; then | |
local -a extra_fzf_args | |
elif [ "$#" -eq 1 ]; then | |
extra_fzf_args=( | |
--query | |
"'$1" | |
) | |
else | |
echo "Unknown arguments $@" | |
return 1 | |
fi | |
# list worktrees, choose with fzf, split the output by whitespace into a zsh array | |
chosen=($(git worktree list | fzf -1 "$extra_fzf_args[@]")) | |
if [ $? -ne 0 ]; then | |
echo "Exiting" | |
return $? | |
fi | |
echo "Going to $chosen" | |
cd "$chosen[1]" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo: