Last active
August 29, 2015 14:11
-
-
Save stephenharris/611fabdb584745e6ad9b to your computer and use it in GitHub Desktop.
Creates a Git command to list all branches and their descriptions.
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
#!/bin/bash | |
# Adapted from https://github.com/bahmutov/git-branches/ | |
# License: MIT | |
# Place in executable path. Name the file git-branchdes | |
# Execute with the command git branchdes | |
# @see https://gist.github.com/stephenharris/611fabdb584745e6ad9b | |
# Store an array of merged branches | |
readarray -t merged <<< "$(git branch --merged)" | |
branch="" | |
branches=`git branch --list` | |
#color codes | |
ESC_SEQ="\x1b[" | |
COL_RESET=$ESC_SEQ"39;49;00m" | |
COL_RED=$ESC_SEQ"31;01m" | |
COL_BLUE=$ESC_SEQ"34;01m" | |
COL_GREEN=$ESC_SEQ"32;01m" | |
# requires git > v.1.7.9 | |
# you can set branch's description using command | |
# git branch --edit-description | |
# this opens the configured text editor, enter message, save and exit | |
# if one editor does not work (for example Sublime does not work for me) | |
# try another one, like vi | |
# you can see branch's description using | |
# git config branch.<branch name>.description | |
printf "\n"; | |
while read -r branch; do | |
# git marks current branch with "* ", remove it | |
clean_branch_name=${branch//\*\ /} | |
description=`git config branch.$clean_branch_name.description` | |
branchname="${clean_branch_name// /}" | |
# Mark current branch red | |
if [ "${branch::1}" == "*" ]; then | |
COL=$COL_RED | |
else | |
# Mark unmerged branches blue | |
# and merged branches green | |
COL=$COL_BLUE | |
for merged_branch in "${merged[@]}" | |
do | |
clean_merged_branch=${merged_branch// /} | |
if [ "$clean_merged_branch" == "$branchname" ] ; then | |
COL=$COL_GREEN | |
break | |
fi | |
done | |
fi | |
printf " $COL%-20s$COL_RESET %-20s\n" "$branchname" "$description" | |
done <<< "$branches" | |
printf "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Future self: I placed this in
/usr/bin/
.