Skip to content

Instantly share code, notes, and snippets.

@samcv
Last active June 24, 2017 17:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save samcv/0bf4dcffc3ac2f01b6d43d1f1085c929 to your computer and use it in GitHub Desktop.
# Git branch with last edited times of the branches and color http://i.imgur.com/BHMLoeA.png
# Needs a newish version of git. if it doesn't work see the version below
gitb_2 () {
git branch --sort=committerdate \
--format='%(if)%(HEAD)%(then)%(color:blue)%(end) %(authordate:relative)%09%(if)%(HEAD)%(then)%(color:green)%(refname:short) *%(else)%(refname:short)%(end)'
}
# Git tag (no color) http://i.imgur.com/24CnCuU.png
alias gitt="git tag --sort='taggerdate' --format=' %(taggerdate:relative)%09%(refname:short)'"
# Like gitb_2 but should work on more systems
gitb () {
if [ "$BASH_VERSION" ] || [ "$ZSH_VERSION" ]; then
green=$'\E[01;32m'
blue=$'\E[01;34m'
default=$'\E[01;39m'
else
green="$(tput setaf 2)"
blue="$(tput setaf 4)"
default="$(tput sgr0)"
fi
branch_name="$(git symbolic-ref HEAD 2>/dev/null)"
branch_name="${branch_name#refs/heads/}"
# escape the branch name for sed
if [ "$BASH_VERSION" ] || [ "$ZSH_VERSION" ]; then
escaped_branch=$(sed 's/[^^]/[&]/g; s/\^/\\^/g' <<<$branch_name )
else
escaped_branch="$(printf "%s" "$branch_name" | sed 's/[^^]/[&]/g; s/\^/\\^/g' )" # escape it
fi
git branch --sort='committerdate' --format=' %(authordate:relative)%09%(refname:short)' "$@" \
| sed -re "s/^(.*\S\s*)${escaped_branch}/${blue}\1${green}${branch_name} \*$default/g"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment