-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitty.sh
303 lines (277 loc) · 8.16 KB
/
gitty.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
#!/bin/bash
##################################################
### giTTY - Your Friendly Version of `git` CLI ###
##################################################
# Parse the command and arguments
# > gitty $COMMAND $ARGUMENTS
COMMAND=$1;
shift
ARUGMENTS=$@;
# Get help with gitty
function gitty_help {
WITH=$1
printf "\n"
printf "##################################################\n"
printf "#### giTTY - Your Friendly Version of git CLI ####\n"
printf "##################################################\n\n"
if [[ $WITH == "" ]]
then
printf "Usage:\n"
printf "\t-h, --help, help: Get help on gitty or any of the following commands\n"
printf "\tsettings: View or configure git configuration\n"
printf "\tcurrent: View the current branch name\n"
printf "\tremote: View the remote branch\n"
printf "\tconnect: Connect local branch to remote branch\n"
printf "\ttrail: See a history of commits\n"
printf "\tnew: Create a new branch\n"
printf "\tupdate: Fetch and pull latest\n"
printf "\tdestroy: Nuke your branch\n"
printf "\tcut: Cut your git changes to be applied later\n"
printf "\tpaste: Paste your cut git changes\n"
printf "\tundo: Undo a previous commit by making a new commit\n"
printf "\tbackpedal: Remove a commit from the history (use sparingly)\n"
else
printf "gitty $WITH [COMMANDS] [FLAGS]\n"
case $WITH in
settings)
printf "\tCOMMANDS:\n"
printf "\t\tshow: Show the current settings for git\n"
printf "\t\tconfig: Change or configure git's settings\n"
printf "\tFLAGS:\n"
printf "\t\t"
;;
current)
;;
*)
;;
esac
fi
printf "\n\n"
}
# Configure git
function gitty_settings {
OPTION=$1
if [[ $OPTION == "help" ]]
then
gitty_help settings
fi
if [[ "$OPTION" == "" || "$OPTION" == "show" ]]
then
echo " Username: `git config --get user.name`"
echo " Email: `git config --get user.email`"
fi
if [[ "$OPTION" == "config" ]]
then
clear
echo "================= Git Settings ================="
select opt in Username Email SSHkey Quit; do
case $opt in
Username)
read -p "Enter the username: " username
git config --global user.username $username
exit 0
;;
Email)
read -p "Enter the email: " email
git config --global user.email $email
exit 0
;;
SSHkey)
ssh-keygen -b 2048 -t rsa -f "$HOME/.ssh/gitty" -q -N '""'
ssh-add "$HOME/.ssh/gitty"
cat "$HOME/.ssh/gitty.pub" | pbcopy
echo "The public RSA key has been copied to your clipboard. Please paste this in your remote repository's SSH Public Keys area."
exit 0
;;
Quit)
exit 0
esac
done
fi
}
# Current Branch
function gitty_current {
git branch --show-current
git rev-parse --short HEAD
exit 0
}
# Remote for Current Branch
function gitty_remote {
BRANCH=(git branch --show-current)
git branch -r | Select-String "(?m)^[\s]*\S*\/+$BRANCH$"
exit 0
}
# Connect local to remote branch
function gitty_connect {
echo "================= Connect to Remote ================="
LOCALBRANCH=`git branch --show-current`
REMOTEOPTIONS=`git branch -r | grep "(?m)^[\s]*\S*\/+$LocalBranch$"`
select opt in $REMOTEOPTIONS; do
git branch --set-upstream-to=$opt $LOCALBRANCH
done
exit 0
}
# Commit History
function gitty_trail {
if [[ $1 == "" ]]
then
NUMBER="--all"
else
NUMBER="-n $1"
fi
git log --graph --abbrev-commit --decorate --format=format:'%C(bold red)%h%C(reset) - %C(bold green)(%cr)%C(reset) %C(bold white)- %an%C(reset)%C(bold yellow)%d%C(reset)' $NUMBER
exit 0
}
# Create New Branch
function gitty_new {
BRANCH=$1
SOURCE=$2
git checkout $SOURCE
git fetch
git pull
git checkout -b $BRANCH $SOURCE
exit 0
}
# Fetch and Pull
function gitty_update {
git fetch
git pull
exit 0
}
# Stash Changes
function gitty_cut {
git stash
exit 0
}
# Apply Stashed Changes
function gitty_paste {
git stash pop
exit 0
}
# Undo commit with commit
function gitty_undo {
if [[ $1 == "" ]]
then
echo " You must specify the Commit Hash: (gitty undo 96370d54)"
exit 1
else
clear
echo "================= Undo Changes from Commit $1 ================="
select opt in "Make a commit with the undo changes" "Make the changes, but don't commit yet" Quit
do
case $opt in
"Make a commit with the undo changes")
git revert --edit $1
;;
"Make the changes, but don't commit yet")
git revert --no-edit $1
;;
Quit)
exit 0
;;
esac
done
exit 0
fi
}
# Delete commit
function gitty_backpedal {
clear
echo "================= Delete Commit `git rev-parse --short HEAD` ================="
git log -1
select opt in "Delete commit, but keep track of changes" "Delete commit, do not track, but keep changes" "Delete commit, do not track, and delete all changes" Quit
do
case $opt in
"Delete commit, but keep track of changes")
git reset --soft HEAD~1
;;
"Delete commit, do not track, but keep changes")
git reset --mixed HEAD~1
;;
"Delete commit, do not track, and delete all changes")
git reset --hard HEAD~1
;;
Quit)
exit 0
;;
esac
done
exit 0
}
if [[ $COMMAND == "" || $COMMAND == "-h" || $COMMAND == "--help" || $COMMAND == "help" ]]
then
gitty_help $ARUGMENTS
else
case $COMMAND in
settings)
gitty_settings $ARUGMENTS
;;
current)
gitty_current $ARUGMENTS
;;
remote)
gitty_remote $ARUGMENTS
;;
connect)
gitty_connect $ARUGMENTS
;;
trail)
gitty_trail $ARUGMENTS
;;
new)
gitty_new $ARUGMENTS
;;
update)
gitty_update $ARUGMENTS
;;
destroy)
gitty_destroy $ARUGMENTS
;;
cut)
gitty_cut $ARUGMENTS
;;
paste)
gitty_paste $ARUGMENTS
;;
undo)
gitty_undo $ARUGMENTS
;;
backpedal)
gitty_backpedal $ARUGMENTS
;;
-*)
git checkout "${COMMAND:1}"
;;
*)
git $COMMAND $ARUGMENTS
;;
esac
fi
exit 0
# function gitty_destroy {
# if [[ $1 == "" ]]
# then
# echo " You must specify the branch: (gitty destroy develop)"
# exit 1
# else
# clear
# echo "================= Destroy $1 ================="
# select opt in "Destroy only the local copy of $1" "Destroy both
# remote & local copies of $1" Quit; do
# case $opt in
# "Destroy only the local copy of $1")
# git checkout master
# git branch -d $1
# ;;
# "Destroy both remote & local copies of $1")
# git checkout master
# git branch -D $1
# ;;
# Quit)
# exit 0
# ;;
# esac
# done
# exit 0
# fi
# }