Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Last active June 15, 2018 00:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eklitzke/c2e78952e7b961a67305ff9ec5487015 to your computer and use it in GitHub Desktop.
Save eklitzke/c2e78952e7b961a67305ff9ec5487015 to your computer and use it in GitHub Desktop.
# 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