forked from paulirish/git-recent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-recent
executable file
·63 lines (56 loc) · 1.58 KB
/
git-recent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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))
format="\
$branch %(HEAD) | \
%(color:bold red)%(objectname:short)%(color:reset) | \
%(color:bold green)(%(committerdate:relative))%(color:reset) | \
%(color:bold blue)%(authorname)%(color:reset) | \
%(contents:subject)"
lessopts="--tabs=4 --quit-if-one-screen --RAW-CONTROL-CHARS --no-init"
branch=$(git for-each-ref \
--color=always \
--count=$COUNT \
--sort=-committerdate \
"refs/heads/" \
--format="$format" \
| column -ts '|' \
| fzf --ansi --layout=reverse --bind='left-click:accept' --nth=1 | awk '{ print $1 }')
git checkout $branch
# 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