-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-shortcuts
104 lines (92 loc) · 1.94 KB
/
git-shortcuts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
gitcommands=( "show" "co" "checkout" "diff" "add" "patch" )
contains() {
isSet=false
for command in ${gitcommands[@]}; do
if [[ "$1" == $command ]]; then
isSet=true
break
fi
done
echo "$isSet"
}
gitfunc() {
local hasCommand=$(contains $1)
if [ $hasCommand == true ]; then
case "$1" in
show)
git show --pretty="format:" --name-only $1
;;
esac
fi
}
prettygit () {
if [ -z "$1" ]
then
echo "ERROR: Must provide a git hash"
else
git show --pretty="format:" --name-only $1
fi
}
function gitcheckout() {
if [ -z "$1" ]; then
echo "ERROR: Must provide a branch name or file path"
else
for i in $*; do
git co $i
done
# git co $1
fi
}
function gitdiff() {
if [ -z "$1" ]; then
echo "ERROR: Must provide a file path"
else
for i in $*; do
git diff $i
done
fi
}
function gitadd() {
if [ -z "$1" ]; then
echo "ERROR: Must provide a file path"
else
for i in $*; do
git --no-pager add $i
done
# git add $1
fi
}
function gitpatch() {
if [ -z "$1" ]; then
echo "ERROR: Must provide a file path"
else
for i in $*; do
git --no-pager co $i
done
# git add -p $1
fi
}
function gitlog() {
local re="^[0-9]+$"
local num=5
local flags="--decorate"
local oneline=false
for i in $*; do
if [ "$i" == "--oneline" ]; then
local flags+=" --oneline"
fi
if [[ "$i" =~ $re ]]; then
local num=$i
fi
done
git --no-pager log $flags -n $num
}
function gitconflict() {
if [ -z "$1" ]; then
echo "ERROR: Must provide a file path"
else
for i in $*; do
git co --conflict=diff3 $i
done
fi
}