]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/git-branch-dates
bin/git-branch-dates: Don't sort by committerdate
[dotfiles.git] / bin / git-branch-dates
1 #!/bin/bash
2 # Usage: git-branch-dates
3 # Show git branches by date - useful for showing active branches
4 # Inspired by:
5 # - http://www.commandlinefu.com/commands/view/2345/show-git-branches-by-date-useful-for-showing-active-branches
6 # - https://stackoverflow.com/a/30076212
7
8 format='%(HEAD) %(color:green)%(refname:short)%(color:reset)|%(color:bold black)%(committerdate:relative)%(color:reset)'
9 if [[ "$1" = "-v" || "$1" = "-vv" ]]; then
10 shift
11 format="$format"'|%(color:yellow)%(objectname:short)%(color:reset) %(contents:subject)'
12 fi
13
14 # For the `cut`-based line truncation handling below, since `cut` works based
15 # on chars/bytes and since the `git branch` will contain SGR escape sequences
16 # for coloring, predict how many "extra" bytes will be in each line due to the
17 # coloring in the `format` defined above.
18 extra_color_len=26
19
20 git branch \
21 --color=always \
22 --format="$format" \
23 $* \
24 | column -ts'|' \
25 | cut -c 1-$(expr $(tput cols) + $extra_color_len)