mirror of
https://github.com/paulirish/git-recent.git
synced 2026-09-10 07:26:16 -04:00
74 lines
1.9 KiB
Bash
Executable file
74 lines
1.9 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
##
|
|
## git-recent
|
|
##
|
|
## list all local branches, sorted by last commit, formatted reall purdy
|
|
##
|
|
|
|
# Windows needs more basic format (#8, git-for-windows/git#865)
|
|
case $(uname -s) in
|
|
CYGWIN*|MINGW*|MSYS*)
|
|
branch='%(refname:short)'
|
|
spacer=' '
|
|
;;
|
|
*)
|
|
branch='%(color:yellow)%(refname:short)%(color:reset)'
|
|
spacer='%(color:black) %(color:reset)'
|
|
;;
|
|
esac
|
|
|
|
COUNT=0
|
|
while getopts "n:" opt; do
|
|
case ${opt} in
|
|
n )
|
|
if ! [[ $OPTARG =~ ^[0-9]{1,}$ ]]; then
|
|
echo "-n should be an integer."
|
|
exit 1
|
|
fi
|
|
COUNT=${OPTARG}
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
shift $((OPTIND-1))
|
|
|
|
# Dont collect upstream details ("[ahead 2, behind 54]"") for big-ass git repos. It's slow.
|
|
# TODO: count-object -v is slow. Maybe store setting in repo config somehow
|
|
obj_count=$(git count-objects -v 2>/dev/null | grep -- "in-pack" | cut -d " " -f 2)
|
|
if [ "$obj_count" -gt "5000000" ]; then
|
|
upstream_deets=""
|
|
else
|
|
upstream_deets="%(color:yellow)%(upstream:track)%(color:reset)"
|
|
fi
|
|
|
|
format="\
|
|
$branch %(HEAD)\
|
|
|
|
%(color:bold red)%(objectname:short)%(color:reset) \
|
|
%(color:bold green)(%(committerdate:relative))%(color:reset) \
|
|
%(color:bold blue)%(authorname)%(color:reset) \
|
|
$upstream_deets
|
|
%(contents:subject)
|
|
"
|
|
|
|
lessopts="--tabs=4 --quit-if-one-screen --RAW-CONTROL-CHARS --no-init"
|
|
|
|
git for-each-ref \
|
|
--color=always \
|
|
--count=$COUNT \
|
|
--sort=-committerdate \
|
|
"refs/heads/" \
|
|
--format="$format" \
|
|
| less "$lessopts"
|
|
|
|
# The above command:
|
|
# for all known branches,
|
|
# (force coloring on this, especially since it's being piped)
|
|
# optionally, specify the number of branches you want to display
|
|
# sort descending by last commit
|
|
# show local branches (change to "" to include both local + remote branches)
|
|
# apply the formatting template above
|
|
# break into columns
|
|
# use the pager only if there's not enough space
|