-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcgit
More file actions
263 lines (215 loc) · 4.41 KB
/
cgit
File metadata and controls
263 lines (215 loc) · 4.41 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
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
#!/bin/bash
# variables
cona="commit name: "
brna="branch name: "
repourl="repo url: "
lv=$(curl --silent "https://api.github.com/repos/secman-team/corgit/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
ver="cgit@$lv"
crepo="Dev-x-Team/corgit"
UNAME=$(uname)
function usage() {
local u=(
"Usage:"
" cgit -h: help (this output)"
" cgit -d: show description"
" cgit -v: corgit version"
" cgit -dv: show corgit repo"
" cgit i: init \".git\" and push origin"
" cgit s: status"
" cgit sl: show the status of git by list view"
" cgit e: push an existing repo"
" cgit ph: push and commit"
" cgit pl: fetch and pull"
" "
"you can open an issue if you had any problem in https://github.com/$crepo/issues"
)
printf "%s\n" "${u[@]}"
}
function badUsage() {
local msg="$1"
local txt=(
"For an overview of the command, execute:"
"cgit -h"
)
[[ $msg ]] && printf "$msg\n"
printf "%s\n" "${txt[@]}"
}
function version() {
local v=(
"$ver"
)
printf "%s\n" "${v[@]}"
}
function desc() {
local d=(
"CorGit is a Cli program can automate init git, push commits and pull."
)
printf "%s\n" "${d[@]}"
}
ysa() {
# ysa = you should accept
echo "you should accept to install"
exit 0
}
initx() {
# init
git init
git add .
echo "$cona"
echo " "
read cn
git commit -m "$cn"
echo "$brna"
echo " "
read bn
git branch -M $bn
echo $repourl
echo " "
read url
git remote add origin $url
git push -u origin $bn
}
einit() {
# init
git init
}
noGit() {
# if the dic doesn't has .git folder
echo -e "There's no .git folder... so would you want to init it ?\n[Y/n]"
read -n 1 accept
if [[ $accept == "" || $accept == "Y" || $accept == "y" ]]; then
initx
else
ysa
fi
}
statusList() {
# show git status in list view
# if [ -x "$(command -v colorls)" ]; then
# colorls --git-status
# else
# echo -e "there's no colorls, you can install it by type\n gem install colorls"
# fi
if [[ "$UNAME" == "Linux" || "$UNAME" == "Darwin" ]]; then
if [ -x "$(command -v colorls)" ]; then
colorls -al --git-status
else
echo -e "there's no colorls\ndo you want to install it\n[Y/n]"
read -n 1 accept
if [[ $accept == "" || $accept == "Y" || $accept == "y" ]]; then
sudo gem install colorls
if [ -x "$(command -v colorls)" ]; then
colorls -al --git-status
fi
else
ysa
fi
fi
else
echo "colorls does not support this system 😔"
fi
}
dvf() {
if [ -x "$(command -v secman)" ]; then
secman repo view $crepo
else
echo "You must install github cli, https://cli.github.com"
fi
}
pushx() {
# push
if [ -d ".git" ]; then
git status
git add .
echo $cona
echo " "
read cn
git commit -m "$cn"
git push
else
noGit
fi
}
pullx() {
# pull
if [ -d ".git" ]; then
git pull
else
einit
fi
}
status() {
# status
if [ -d ".git" ]; then
git status
else
noGit
fi
}
exrepo() {
if [ -d ".git" ]; then
echo "$repourl"
echo " "
read url
echo "$brna"
echo " "
read bn
git remote add origin $url
git branch -M $bn
git push -u origin $bn
else
einit
fi
}
if [ $# -eq 0 ]; then
usage
exit 0
fi
while (($#)); do
case "$1" in
--help | -h)
usage
exit 0
;;
version | --version | -v)
version
exit 0
;;
--desc | --description | -d)
desc
exit 0
;;
-dv)
dvf
exit 0
;;
status | s)
status
exit 0
;;
sl)
statusList
exit 0
;;
init | i)
initx
exit 0
;;
e)
exrepo
exit 0
;;
push | ph)
pushx
exit 0
;;
pull | pl)
pullx
exit 0
;;
*)
badUsage "Option/command not recognized."
exit 0
;;
esac
done