-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitHelper.sh
More file actions
executable file
·117 lines (106 loc) · 4.27 KB
/
gitHelper.sh
File metadata and controls
executable file
·117 lines (106 loc) · 4.27 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
## This script parse git status and allow you to reset all files that are currently cached or can take input (copy and paste)
## and will run git add [FILENAME] on the list of files
##Example input
##========================================================
# modified: norse/folk/norcaltda/www/cms/header.html
# modified: norse/folk/norcaltda/www/cms/index.css
# modified: norse/folk/norcaltda/www/cms/index.html
# modified: norse/folk/norcaltda/www/cms/index22.html
# modified: norse/folk/norcaltda/www/cms/indexnofb.html
# modified: norse/folk/norcaltda/www/cms/jqModal.css
# modified: norse/folk/norcaltda/www/cms/jquery-ui-timepicker-addon.js
# modified: norse/folk/norcaltda/www/cms/login.js
# modified: norse/folk/norcaltda/www/cms/main.js
# modified: norse/folk/norcaltda/www/cms/main2.js
# modified: norse/folk/norcaltda/www/cms/main_my.js
# modified: norse/folk/norcaltda/www/cms/mainpublish.html
# modified: norse/folk/norcaltda/www/cms/myaccount.js
# modified: norse/folk/norcaltda/www/cms/register.html
# modified: norse/folk/norcaltda/www/cms/register.js
#!/bin/sh
# Linux users have to change $8 to $9
option=$1
#echo $option
if [ "$option" = "help" ] || [ "$option" = "" ] ; then
echo "This bash script runs git status and captures the files to either reset, add or add untracked."
echo " Use 'reset' to reset all files from HEAD. (e.g. ./gitHelper.sh reset) "
echo " Use 'add' to add all files unstaged for commit."
echo " Use 'untracked' to add all untracked files to commit"
echo " Use 'delete' to remove all deleted files to commit"
fi
#reset all files
if [ "$option" = "reset" ] ; then
var=`git status -s | awk '/^([MAD]|AM)[ ].*/{print $2}' | xargs -L1 echo `
if [ "$var" = "" ] ; then
echo "No added files to reset. None reset from HEAD."
else
echo "RESETTING the files below: "
echo "======================================================"
echo "$var"
echo " "
echo "Results: "
echo "======================================================"
var=`git status -s | awk '/^([MAD]|AM)[ ].*/{print $2}' | xargs -L1 git reset HEAD -q `
if [ "$var" != "" ] ; then
echo "$var"
else
var=`git status -s | awk '/^[ ]M[ ].*/{print "Unstaged for Commit: \033[0;31m" $2 "\033[0m"}'`
echo "$var"
var=`git status -s | grep ?? | awk '{print "Untracked: \033[0;34m" $2 "\033[0m"}'`
echo "$var"
var=`git status -s | awk '/^[ ]D[ ].*/{print "Unstaged for Delete: \033[0;35m" $2 "\033[0m"}' `
echo "$var"
fi
fi
fi
#add all modified files
if [ "$option" = "add" ] ; then
var=`git status -s | awk '/^[ ]M[ ].*/{print $2}' | xargs -L1 echo `
if [ "$var" = "" ] ; then
echo "No modified files to add to git. None added."
else
echo "ADDING the files below: "
echo "======================================================"
echo "$var"
echo " "
echo "Results: "
echo "======================================================"
var=`git status -s | awk '/^[ ]M[ ].*/{print $2}' | xargs -L1 git add `
var=`git status -s | awk '/^([MA]|AM)[ ].*/{print "Staged for Commit: \033[0;32m" $2 "\033[0m"}' `
echo "$var"
fi
fi
#add all untracked files
if [ "$option" = "untracked" ] ; then
var=`git status -s | grep ?? | awk '{print $2}' | xargs -L1 echo`
if [ "$var" = "" ] ; then
echo "No untracked files to add. None added."
else
echo "ADDING the untracked files below: "
echo "======================================================"
echo "$var"
echo " "
echo "Results: "
echo "======================================================"
var=`git status -s | grep ?? | awk '{print $2}' | xargs -L1 git add `
var=`git status -s | awk '/^([MA]|AM)[ ].*/{print "Staged for Commit: \033[0;34m" $2 "\033[0m"}' `
echo "$var"
fi
fi
#delete all untracked files
if [ "$option" = "delete" ] ; then
var=`git status -s | awk '/^[ ]D[ ].*/{print $2}' | xargs -L1 echo`
if [ "$var" = "" ] ; then
echo "No deleted files to remove."
else
echo "DELETING the files below: "
echo "======================================================"
echo "$var"
echo " "
echo "Results: "
echo "======================================================"
var=`git status -s | awk '/^[ ]D[ ].*/{print $2}' | xargs -L1 git rm `
var=`git status -s | awk '/^D[ ].*/{print "Staged for Delete: \033[0;35m" $2 "\033[0m"}' `
echo "$var"
fi
fi