-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_git
More file actions
122 lines (102 loc) · 2.19 KB
/
bash_git
File metadata and controls
122 lines (102 loc) · 2.19 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
isInString() {
if [[ $1 == *"$2"* ]] && [ -n "$2" ]
then
return 0
fi
return 1
}
status() {
# Get 'git status -s' with colors :)
filelines=$(git status -s | cat)
oldIFS="$IFS"
IFS='
'
IFS=${IFS:0:1} # this is useful to format your code with tabs
lines=( $filelines )
IFS="$oldIFS"
for index in "${!lines[@]}"
do
diplay_index=$(($index + 1))
echo "$diplay_index ${lines[index]}"
done
}
diff() {
filelines=$(git status -s | cut -c 4-)
oldIFS="$IFS"
IFS='
'
IFS=${IFS:0:1} # this is useful to format your code with tabs
lines=( $filelines )
IFS="$oldIFS"
for index in "${!lines[@]}"
do
diplay_index=$(($index + 1))
if isInString $1 $diplay_index
then
git diff ${lines[index]}
fi
done
}
checkout() {
filelines=$(git status -s | cut -c 4-)
oldIFS="$IFS"
IFS='
'
IFS=${IFS:0:1} # this is useful to format your code with tabs
lines=( $filelines )
IFS="$oldIFS"
for index in "${!lines[@]}"
do
diplay_index=$(($index + 1))
if isInString $1 $diplay_index
then
git checkout ${lines[index]}
fi
done
}
commit() {
if [[ $1 == "-a" ]]
then
add
fi
read -p "Message: " message
git commit -m "$message"
}
add() {
status
read -p "Files to add: " filesToAdd
filelines=$(git status -s | cut -c 4-)
oldIFS="$IFS"
IFS='
'
IFS=${IFS:0:1} # this is useful to format your code with tabs
lines=( $filelines )
IFS="$oldIFS"
oldIFS="$IFS"
IFS=","
files=( $filesToAdd )
IFS="$oldIFS"
for index in "${!lines[@]}"
do
diplay_index=$(($index + 1))
for fileIndex in "${!files[@]}"
do
if [ "$diplay_index" == "${files[fileIndex]}" ]
then
echo "$diplay_index ${lines[index]}"
git add ${lines[index]}
fi
done
done
}
function log {
num_commits=10
if [ -n "$1" ]
then
num_commits=$1
fi
git log -n $num_commits --graph --abbrev-commit --decorate --format=format:' %C(bold yellow)%an%C(reset) - %C(bold green)%ar%C(reset)%C(bold blue)%d%C(reset)%n'' %C(black)%s%C(reset)' --all
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/'
}