Skip to content

Instantly share code, notes, and snippets.

@hkupty
Created December 18, 2019 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkupty/2b5a306092f4254349d384a2e0a617e1 to your computer and use it in GitHub Desktop.
Save hkupty/2b5a306092f4254349d384a2e0a617e1 to your computer and use it in GitHub Desktop.
Fuzzy-find branches in git repo
#!/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