Skip to content

Instantly share code, notes, and snippets.

@jeenuv
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save jeenuv/3145db36eb2a27ba022a to your computer and use it in GitHub Desktop.

Select an option

Save jeenuv/3145db36eb2a27ba022a to your computer and use it in GitHub Desktop.
Print descriptions of all local branches
#!/bin/bash
# For each branch in the repository, get the branch description from
# Git config, and print in a neat fashion
[ -d .git ] || exit 1
git for-each-ref refs/heads --format='%(refname:short)' | grep -v '\.stgit' |
xargs bash -c '
head="$(git symbolic-ref --short HEAD)"
for br; do
desc=$(git config --get branch.$br.description | head -n1 )
if [ "$head" = "$br" ]; then
# Print the current branch in green foreground
#
# Terminal control characters are counted for calculating width of field,
# but does not appear as characters in the terminal output. Therefore it
# affects alignment To balance "missing" characters, we add 5 trailing
# white spaces per `tput` to the branch field
printf " * %-60s%-10s%s\n" "$(tput setaf 2)$br$(tput setaf 9)" "" "$desc"
else
printf " * %-60s%s\n" "$br" "$desc"
fi
done' bash
# vim:set tw=80 sw=2:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment