Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created August 6, 2020 15:59
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 seven1m/8c87fccb2535e74b835f0d9dcb878747 to your computer and use it in GitHub Desktop.
Save seven1m/8c87fccb2535e74b835f0d9dcb878747 to your computer and use it in GitHub Desktop.
Alias I use for switching branches
# fuzzy finder branch selection
# if run by itself, switches to the selected branch
# if run in a subshell, echos the selected branch
function fgb() {
if [[ "$ZSH_SUBSHELL" == "0" ]]; then
git checkout $(fgb)
else
gbranches |
fzf --height 40% --ansi |
awk '{print $1}' |
sed 's#^remotes/[^/]*/##'
fi
}
function gbranches() {
local ansi_reset="\\e[0m"
local ansi_dim="\\e[2m"
local ansi_green="\\e[32m"
local ansi_yellow="\\e[33m"
git branch |
sed 's/^..//' |
ruby -e "puts STDIN.read.split(/\n/).map { |b| b = b.split.first; [b, %x(git log --format='%ai ${ansi_dim}%hi${ansi_reset} ${ansi_yellow}%s${ansi_reset}' #{b} | head -1)] }.sort_by(&:last).reverse.map { |b, c| %(${ansi_green} #{b.ljust(50)} ${ansi_reset} #{c}) }"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment