Last active
March 11, 2016 18:18
-
-
Save pardo/49f61980e5d2695b8d90 to your computer and use it in GitHub Desktop.
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 | |
#http://stackoverflow.com/a/18767922 | |
function gitlist { | |
git branch -vv --color=always | while read; do | |
# The underscore is because the active branch is preceded by a '*', and | |
# for awk I need the columns to line up. The perl call is to strip out | |
# ansi colors; if you don't pass --color=always above you can skip this | |
local branch=$(echo "_$REPLY" | awk '{print $2}' | perl -pe 's/\e\[?.*?[\@-~]//g') | |
# git log fails when you pass a detached head as a branch name. | |
# Hide the error and get the date of the current head. | |
local branch_modified=$(git log -1 --format=%ci "$branch" 2> /dev/null || git log -1 --format=%ci) | |
echo -e "$branch_modified $REPLY" | |
# cut strips the time and timezone columns, leaving only the date | |
done | sort -r | cut -d ' ' -f -1,4- | |
} | |
if [ "$1" == "-a" ]; then | |
gitlist | |
else | |
gitlist | head -n 14 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment