Created
August 6, 2020 15:59
-
-
Save seven1m/8c87fccb2535e74b835f0d9dcb878747 to your computer and use it in GitHub Desktop.
Alias I use for switching branches
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
# 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