From e373059faeeb0835fde58b93f11b99931e8b8055 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Fri, 13 Apr 2018 20:42:54 -0500 Subject: [PATCH] bin/git-branch-dates: Show git branches with dates, sort by commiterdate --- .gitconfig | 2 +- bin/git-branch-dates | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitconfig b/.gitconfig index 3a5ef17..c5914a7 100644 --- a/.gitconfig +++ b/.gitconfig @@ -17,7 +17,7 @@ out = !git-outgoing # Branch helpers bd = !git-branch-dates - bv = !git branch --color -vv + bv = !git-branch-dates -v cv = !git-cherry-view # Diff helpers df = diff diff --git a/bin/git-branch-dates b/bin/git-branch-dates index 7922302..a33fa00 100755 --- a/bin/git-branch-dates +++ b/bin/git-branch-dates @@ -1,8 +1,17 @@ #!/bin/bash -# Usage: git-brdate +# Usage: git-branch-dates # Show git branches by date - useful for showing active branches -# http://www.commandlinefu.com/commands/view/2345/show-git-branches-by-date-useful-for-showing-active-branches +# Inspired by: +# - http://www.commandlinefu.com/commands/view/2345/show-git-branches-by-date-useful-for-showing-active-branches +# - https://stackoverflow.com/a/30076212 -for k in `git branch | perl -pe s/^..//`; do - echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k | head -n 1`\\t$k -done | sort -r +format='%(HEAD) %(color:green)%(refname:short)%(color:reset)|%(color:bold black)%(committerdate:relative)%(color:reset)' +if [[ "$1" = "-v" || "$1" = "-vv" ]]; then + shift + format="$format"'|%(color:yellow)%(objectname:short)%(color:reset) %(contents:subject)' +fi +git branch \ + --color=always \ + --sort=-committerdate \ + --format="$format" \ + $* | column -ts'|' -- 2.45.2