Skip to content

Instantly share code, notes, and snippets.

@sgolemon
Created September 27, 2017 16:04
Show Gist options
  • Save sgolemon/66e72ad6f65acb77b04ff00ef5b68ff4 to your computer and use it in GitHub Desktop.
Save sgolemon/66e72ad6f65acb77b04ff00ef5b68ff4 to your computer and use it in GitHub Desktop.
My `git branches` command
#!/bin/bash
set -e
branches=$(git branch | cut -c 2-)
len=0
for branch in $branches; do
if [ $len -lt ${#branch} ]; then
len=${#branch}
fi
done
current=$(git branch | grep -E '^\*' | cut -c 3-)
for branch in $branches; do
subject=$(git log -1 --format="%s" "$branch" | grep -vE '^gpg:')
if [ "$current" = "$branch" ]; then
echo -en "\e[32m"
fi
printf "%-${len}s %s\e[0m\n" "$branch" "$subject"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment