Last active
June 15, 2018 00:54
-
-
Save eklitzke/c2e78952e7b961a67305ff9ec5487015 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Like "git branch", but also show colorized (and aligned!) branch descriptions. | |
# Git branch descriptions can be created using "git branch --edit-description". | |
gb() { | |
maxlen=0 | |
branches=$(git for-each-ref --format='%(refname)' refs/heads/ | sed 's|refs/heads/||') | |
for branch in $branches; do | |
len=${#branch} | |
if [ "$len" -gt "$maxlen" ]; then | |
maxlen="$len" | |
fi | |
done | |
current="$(git rev-parse --abbrev-ref HEAD)" | |
for branch in $branches; do | |
len=${#branch} | |
desc=$(git config branch."$branch".description | head -n 1) | |
if [ "$branch" = "$current" ]; then | |
branch="* \033[0;32m$branch\033[0m" | |
else | |
branch=" $branch" | |
fi | |
if [ -n "$desc" ]; then | |
branch="$branch$(printf "%*s" $((maxlen + 5 - len)) "")\033[0;36m$desc\033[0m" | |
fi | |
echo -e "$branch" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment