Created
December 18, 2019 08:19
-
-
Save hkupty/2b5a306092f4254349d384a2e0a617e1 to your computer and use it in GitHub Desktop.
Fuzzy-find branches in git repo
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
#!/bin/bash | |
set -euo pipefail | |
# TODO Fix multiple remotes | |
readarray LOCAL <<< $(git branch --no-color | awk '{print $NF}') | |
readarray REMOTE <<< $(git branch -r | sed 's/.*origin\///g') | |
REMOTE_ONLY=($(echo ${LOCAL[@]} ${LOCAL[@]} ${REMOTE[@]} | tr ' ' '\n' | sort | uniq -u)) | |
fancy(){ | |
for i in $@; do | |
echo -e "\e[32m✦\e[39m $i" | |
done | |
} | |
boring(){ | |
for i in $@; do | |
echo " $i" | |
done | |
} | |
git checkout $(echo -e "$(boring ${LOCAL[@]})\n$(fancy ${REMOTE_ONLY[@]})" | fzf --ansi | awk '{print $NF}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment