forked from iwata/git-now
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gitnow-common
64 lines (51 loc) · 1.67 KB
/
gitnow-common
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
64
#
# Common functionality
#
# shell output
warn() { echo "$@" >&2; }
die() { warn "$@"; exit 1; }
escape() {
echo "$1" | sed 's/\([\.\+\$\*]\)/\\\1/g'
}
# set logic
has() {
local item=$1; shift
echo " $@ " | grep -q " $(escape $item) "
}
# basic math
min() { [ "$1" -le "$2" ] && echo "$1" || echo "$2"; }
max() { [ "$1" -ge "$2" ] && echo "$1" || echo "$2"; }
# basic string matching
startswith() { [ "$1" != "${1#$2}" ]; }
endswith() { [ "$1" != "${1%$2}" ]; }
# convenience functions for checking shFlags flags
flag() { local FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -eq $FLAGS_TRUE ]; }
noflag() { local FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -ne $FLAGS_TRUE ]; }
#
# Git specific common functionality
#
git_local_branches() { git branch --no-color | sed 's/^[* ] //'; }
git_remote_branches() { git branch -r --no-color | sed 's/^[* ] //'; }
git_all_branches() { ( git branch --no-color; git branch -r --no-color) | sed 's/^[* ] //'; }
git_current_branch() {
git rev-parse --abbrev-ref HEAD
}
git_now_first_commit() {
local common=$1
if [ $# -eq 1 ]; then
git log ${common}.. --pretty=oneline --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1
else
git log --pretty=oneline --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1
fi
}
git_now_my_first_commit() {
local author=$(escape `git config --get user.name`)
local common=$1
if [ $# -eq 1 ]; then
git log ${common}.. --pretty=oneline --author=${author} --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1
else
git log --pretty=oneline --author=${author} --grep="${PREFIX}" | tail -n 1 | cut -d " " -f 1
fi
}
git_now_initial_commit() { git log --pretty=oneline | tail -n 1 | cut -d " " -f 1; }
# vim: set ff=unix ft=sh