-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitgeek.sh
executable file
·526 lines (481 loc) · 14.4 KB
/
gitgeek.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
#!/bin/sh
# ==================================================================
# @Author: Jefferson Cechinel
# @Email: [email protected]
# @Date: 2015-08-30 16:26:28
# ------------------------------------------------------------------
#
# GitGeek (gitgeek) - v0.1
# This is a simple bash script utility that speeds up the repetitive tasks
# by automating in a few strokes the use of git application in a very fashion
# prompt menu way.
#
# By default it will prompt you to configure the git project bt setting your real name and
# e-mail address if it is not set yet.
#Stop git from converting end lines LF(unix) to CRLF(windows).
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
OPTION=""
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under GNU/Linux platform
OPTION="-e"
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
# Do something under Windows NT platform
OPTION="-e"
fi
git config core.autocrlf false
# Colors
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"
clear
echo ""
echo " ____ _ _ ____ _ "
echo " / ___(_) |_ / ___| ___ ___| | __"
echo "| | _| | __| | _ / _ \/ _ \ |/ /"
echo "| |_| | | |_| |_| | __/ __/ < "
echo " \____|_|\__|\____|\___|\___|_|\_\\"
echo ""
echo $OPTION $COL_YELLOW"GIT Geek - Verson 0.1 (Jefferson Cechinel)"$COL_RESET
echo ""
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
# if [ -z "$BRANCH" ]; then
# echo "You have no branches at this moment. You need at least one branch to run this script."
# exit
# fi
echo $OPTION "You are working in branch: $COL_GREEN $BRANCH $COL_RESET"
echo "List of branches in this repository:"
git branch
echo ""
NAME=`git config user.name`
EMAIL=`git config user.email`
if [ -z "$NAME" ]; then
read -p "Full Name for this project (git config user.name): " tname
git config user.name "$tname"
echo ""
fi
if [ -z "$EMAIL" ]; then
read -p "Email address for this project (git config user.email): " temail
git config user.email "$temail"
echo ""
fi
commit()
{
read -p "Type the commit message:" msg
echo "Adding all files.."
echo $OPTION $COL_MAGENTA"git add . $COL_RESET"
git add .
echo "Checking git status.."
echo $OPTION $COL_MAGENTA"git status $COL_RESET"
git status
echo "Commiting with message: $msg"
echo $OPTION $COL_MAGENTA"git commit -a -m "$msg" $COL_RESET"
git commit -a -m "$msg"
refresh
}
commitpush()
{
read -p "Type the commit message:" msg
echo "Adding all files.."
echo $OPTION $COL_MAGENTA"git add . $COL_RESET"
git add .
echo "Checking git status.."
echo $OPTION $COL_MAGENTA"git status $COL_RESET"
git status
echo "Commiting with message: $msg"
read -p "Perform git commit? (y/n):" yn
if [ "$yn" != "y" ]; then
refresh
return
fi
echo $OPTION $COL_MAGENTA"git commit -a -m "$msg" $COL_RESET"
git commit -a -m "$msg"
echo "Pushing to remotes..."
IFS=$'\n'
arr=($(git remote -v |grep "(push)"| sed 's/:.*//'))
unset IFS
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
for i in "${arr[@]}"
do
DST=`echo $i | cut -d " " -f1`
read -p "Push to $DST? (y/n):" yn
if [ "$yn" == "y" ]; then
echo $OPTION $COL_MAGENTA"git push $DST $BRANCH $COL_RESET"
git push $DST $BRANCH
fi
done
refresh
}
autocommit()
{
msg="Auto commited."
echo -n "Deleting caching files if any... "
rm -rf data/log/* data/cache/*.php
echo "OK"
echo "Adding all files.."
echo $OPTION $COL_MAGENTA"git add . $COL_RESET"
git add .
echo "Checking git status.."
echo $OPTION $COL_MAGENTA"git status $COL_RESET"
git status
echo "Commiting with message: $msg"
echo $OPTION $COL_MAGENTA"git commit -a -m $msg $COL_RESET"
git commit -a -m "$msg"
echo "Pushing to all remotes..."
IFS=$'\n'
arr=($(git remote -v |grep "(push)"| sed 's/:.*//'))
unset IFS
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
for i in "${arr[@]}"
do
DST=`echo $i | cut -d " " -f1`
echo $OPTION $COL_MAGENTA"git push $DST $BRANCH $COL_RESET"
git push $DST $BRANCH
done
refresh
}
merge_deploy()
{
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
if [ "$BRANCH" == "master" ];then
echo $OPTION "You cannot merge current branch ($COL_GREEN $BRANCH $COL_RESET) into ($COL_YELLOW master $COL_RESET)"
return
fi
echo $OPTION "You are about to merge the current branch ($COL_GREEN $BRANCH $COL_RESET) into ($COL_YELLOW master $COL_RESET)."
read -p "Do you really want to merge? (y/n): " yn
if [ "$yn" != "y" ];then
echo "Aborting..."
refresh
return
fi
echo "Checking out master.."
echo $OPTION $COL_MAGENTA"git checkout master $COL_RESET"
git checkout master
echo $OPTION "Merging $COL_GREEN $BRANCH $COL_RESET into $COL_YELLOW master $COL_RESET."
echo $OPTION $COL_MAGENTA"git merge $BRANCH $COL_RESET"
git merge $BRANCH
echo "Pushing to remote master"
IFS=$'\n'
arr=($(git remote -v |grep "(push)"| sed 's/:.*//'))
unset IFS
for i in "${arr[@]}"
do
DST=`echo $i | cut -d " " -f1`
read -p "Push to master? (y/n):" yn
if [ "$yn" == "y" ]; then
echo $OPTION $COL_MAGENTA"git push $DST master $COL_RESET"
git push $DST master
fi
done
echo $OPTION $COL_MAGENTA"git checkout $BRANCH $COL_RESET"
git checkout $BRANCH
refresh
}
checkout()
{
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
IFS=$'\n'
arr=($(git branch | grep -v "*" | grep -v "grep" | cut -d '*' -f2 | xargs))
unset IFS
PS3=`echo $OPTION $COL_YELLOW"Choose a branch ($COL_MAGENTA checkout $COL_RESET): "$COL_RESET`
counter=0
for i in "${arr[@]}"
do
DST=`echo $i`
options2[$counter]=$DST
counter=$((counter+1))
done
options2[$counter]="Back to main menu"
select opt2 in "${options2[@]}"
do
if [ "$opt2" == "Back to main menu" ]; then
refresh
return
fi
echo $OPTION $COL_MAGENTA"git checkout $opt2 $COL_RESET"
git checkout $opt2
return
done
refresh
}
merge_destination_branch()
{
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
if [ "$BRANCH" == "master" ];then
echo "It is not good practice to merge 'master' into another branch."
echo "Consider using 'Merge Working Branch' instead."
echo "Aborting..."
refresh
return
fi
echo $OPTION "You are about to merge the contents of ($COL_GREEN $BRANCH $COL_RESET) into another branch"
IFS=$'\n'
arr=($(git branch | grep -v "*" | grep -v "grep" | cut -d '*' -f2 | xargs))
unset IFS
PS3=`echo $OPTION $COL_YELLOW"Choose a destination branch ($COL_MAGENTA merge $COL_RESET): "$COL_RESET`
counter=0
for i in "${arr[@]}"
do
DST=`echo $i`
options2[$counter]=$DST
counter=$((counter+1))
done
options2[$counter]="Back to main menu"
select opt2 in "${options2[@]}"
do
if [ "$opt2" == "Back to main menu" ]; then
refresh
return
fi
echo $OPTION $COL_MAGENTA"git merge $opt2 $COL_RESET"
#echo git merge $opt2
echo "Checking out $opt2: "
echo $OPTION $COL_MAGENTA"git checkout $opt2 $COL_RESET"
git checkout $opt2
echo "Merging $BRANCH into $opt2"
echo $OPTION $COL_MAGENTA"git merge $BRANCH $COL_RESET"
git merge $BRANCH
echo $OPTION $COL_MAGENTA"git checkout $BRANCH $COL_RESET"
git checkout $BRANCH
refresh
return
done
}
merge_working_branch()
{
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
IFS=$'\n'
arr=($(git branch | grep -v "*" | grep -v "grep" | cut -d '*' -f2 | xargs))
unset IFS
PS3=`echo $OPTION $COL_YELLOW"Choose a branch ($COL_MAGENTA merge $COL_RESET): "$COL_RESET`
counter=0
for i in "${arr[@]}"
do
DST=`echo $i`
options2[$counter]=$DST
counter=$((counter+1))
done
options2[$counter]="Back to main menu"
select opt2 in "${options2[@]}"
do
if [ "$opt2" == "Back to main menu" ]; then
refresh
return
fi
echo $OPTION "You are about to merge the contents of ($COL_GREEN $opt2 $COL_RESET) into ($COL_GREEN $BRANCH $COL_RESET)"
read -p "Do you want to proceed? (y/n)" yn
if [ "$yn" != "y" ]; then
echo "Aborting..."
refresh
return
fi
echo "Merging $opt2 into $BRANCH"
echo $OPTION $COL_MAGENTA"git merge $opt2 $COL_RESET"
git merge $opt2
refresh
return
done
}
delete_branch()
{
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_GREEN=$ESC_SEQ"32;01m"
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
echo "You are about to permanetly delete a branch."
echo "You cannot delete 'master' and 'develop' branches using this tool for security purposes."
echo "Below is the list of branches this tool is able to delete:"
git branch | grep -v "master" | grep -v "develop"
read -p "Type the branch name you want to delete or leave in blank to cancel the operation:" bname
if [ "$bname" == "master" ];then
echo "You cannot delete the branch $COL_GREEN($bname)$COL_REST using this tool."
echo "Aborting..."
refresh
return
fi
if [ "$bname" == "develop" ];then
echo "You cannot delete the branch ($bname) using this tool."
echo "Aborting..."
refresh
return
fi
if [ "$bname" == "" ];then
refresh
return
fi
echo $OPTION $COL_MAGENTA"git branch -d $bname $COL_RESET"
git branch -d $bname
refresh
}
push()
{
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
IFS=$'\n'
arr=($(git remote -v |grep "(push)"| sed 's/:.*//'))
unset IFS
PS3=`echo $OPTION $COL_BLUE"Choose the remote repository ($COL_MAGENTA push $COL_RESET): "$COL_RESET`
counter=0
for i in "${arr[@]}"
do
DST=`echo $i | cut -d " " -f1`
options2[$counter]=$DST
counter=$((counter+1))
done
options2[$counter]="Back to main menu"
select opt2 in "${options2[@]}"
do
if [ "$opt2" == "Back to main menu" ]; then
refresh
return
fi
echo $OPTION $COL_MAGENTA"git push $opt2 $BRANCH $COL_RESET"
git push $opt2 $BRANCH
done
refresh
}
pull()
{
BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
IFS=$'\n'
arr=($(git remote -v |grep "(push)"| sed 's/:.*//'))
unset IFS
PS3=`echo $OPTION $COL_BLUE"Choose the remote repository ($COL_MAGENTA pull $COL_RESET): "$COL_RESET`
counter=0
for i in "${arr[@]}"
do
DST=`echo $i | cut -d " " -f1`
options2[$counter]=$DST
counter=$((counter+1))
done
options2[$counter]="Back to main menu"
select opt2 in "${options2[@]}"
do
if [ "$opt2" == "Back to main menu" ]; then
refresh
return
fi
echo $OPTION $COL_MAGENTA"git pull $opt2 $BRANCH $COL_RESET"
git pull $opt2 $BRANCH
return
done
refresh
}
status()
{
echo $OPTION $COL_MAGENTA"git status $COL_RESET"
git status
refresh
}
log()
{
echo "Showing last 10 commits.."
echo $OPTION $COL_MAGENTA"git log --graph --decorate --pretty=oneline --abbrev-commit --all $COL_RESET"
git log --graph --decorate --pretty=oneline --abbrev-commit --all
refresh
}
list_branch()
{
echo $OPTION $COL_MAGENTA"git branch --all $COL_RESET"
git branch
refresh
}
about()
{
echo " ____ _ _ ____ _ "
echo " / ___(_) |_ / ___| ___ ___| | __"
echo "| | _| | __| | _ / _ \/ _ \ |/ /"
echo "| |_| | | |_| |_| | __/ __/ < "
echo " \____|_|\__|\____|\___|\___|_|\_\\"
echo ""
echo "Git Geek - A simple bash script utility to speed up the repetitive daily git commands."
echo "Author: Jefferson Cechinel"
echo "E-mail: [email protected]"
echo "Project Website: https://github.com/jeffersoncechinel/dev-scripts.git"
echo ""
}
refresh()
{
echo $OPTION $COL_CYAN"Leave it blank and PRESS ENTER to refresh the command list."$COL_RESET
}
ps3()
{
CUR_BRANCH=`git branch | grep "*" | grep -v "grep" | cut -d '*' -f2 | xargs`
PWD=`basename "$PWD"`
PS3=`printf "\nWorking in project ($COL_GREEN $PWD $COL_RESET) branch ($COL_GREEN $CUR_BRANCH $COL_RESET)\n"$COL_BLUE"Please enter your option number$COL_RESET : "`
}
ps3
options=("Show Status" "Commit" "Commit and Push" "Auto Commit and Push" "Push" "Pull" "List Branches" "Checkout Branch" "Merge Working Branch" "Merge Destination Branch" "Delete Branch" "Merge and Deploy" "Show Remotes" "Log" "About" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Show Status")
status
ps3
;;
"Commit")
commit
ps3
;;
"Commit and Push")
commitpush
ps3
;;
"Auto Commit and Push")
autocommit
ps3
;;
"Push")
push
ps3
;;
"Pull")
pull
ps3
;;
"List Branches")
git branch
ps3
;;
"Checkout Branch")
checkout
ps3
;;
"Merge Working Branch")
merge_working_branch
ps3
;;
"Merge Destination Branch")
merge_destination_branch
ps3
;;
"Delete Branch")
delete_branch
ps3
;;
"Merge and Deploy")
merge_deploy
ps3
;;
"Show Remotes")
git remote -v
ps3
;;
"Log")
log
ps3
;;
"About")
about
ps3
;;
"Quit")
exit
;;
*) echo "Invalid Option! - Press enter to see command list.";;
esac
done