-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-tlog
executable file
·58 lines (51 loc) · 1.39 KB
/
git-tlog
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
#!/bin/bash -e
if [ "$1" = --version ] || [ "$1" = -v ]; then
echo 'git-tlog 0.2'
exit 0
fi
die_with_status () {
status="$1"
shift
echo >&2 "$@"
exit "$status"
}
if [ "$#" -lt 2 ] || [ "$1" = --help ] || [ "$1" = -h ]; then
die_with_status 1 "Usage: $0 [options] <commitish> <commitish>"
fi
program=$(basename "$0")
case $program in
git-tlog)
dots='..'
;;
git-tdiff)
dots='...'
;;
*)
die_with_status 2 "I don't know how to be run as $program; aborting."
;;
esac
baseProgram=$(sed 's/git-t//' <<<"$program")
# Pull the last two parameters out of $@.
# We can extract arbitrary elements using ${@: -2:1} syntax (
# http://stackoverflow.com/a/6428901/120999 ), but it doesn't seem possible to
# remove them from $@ that way. Instead, make a copy, modify that, and reset
# $@ when we're done, as per http://stackoverflow.com/a/6595266/120999 .
a=("$@")
commitishA=${a[$#-2]}
commitishB=${a[$#-1]}
unset a[$#-2]
unset a[$#-1]
set -- "${a[@]}"
if [ -n "$TMUX" ]; then
git $baseProgram $@ $commitishA$dots$commitishB
tmux \
split-window -d -h \
"git $baseProgram $@ $commitishB$dots$commitishA ; $SHELL" \;
else
tmux new \
-s $program \
"git $baseProgram $@ $commitishA$dots$commitishB ; $SHELL" \;\
select-layout tiled \;\
split-window -d -h \
"git $baseProgram $@ $commitishB$dots$commitishA ; $SHELL" \;
fi