-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitpush
More file actions
executable file
·205 lines (178 loc) · 5.47 KB
/
Copy pathgitpush
File metadata and controls
executable file
·205 lines (178 loc) · 5.47 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
#!/bin/bash
######## ###### ########### ######## #####
####### ###### ########### ####### ### ###
####### ## ###### ####### ### ###
### ## ####### ### ### ###
### ## ##### ### ### ###
### ## ###### ### ### ###
######## ## ####### ###### ### ###
####### ###### ########## ####### ### ###
####### ###### ########## ######## #####
# ===========================
# Author: Cisco Ramon
# GitPush v2 (Interactive)
# ===========================
# ---------- Globals ----------
op1="$1"
currentDate=$(date +%b-%d)
currentTime=$(date +%H:%M)
DefaultCommit="Updated on $currentDate at $currentTime"
# ---------- Utils ----------
pause() {
read -p "Press ENTER to continue..."
}
# ---------- Help ----------
Help() {
echo
echo "################################################################"
echo "# Usage: gitpush [options] #"
echo "# #"
echo "# Options: #"
echo "# (no args) : Default add + commit + push #"
echo "# -i : Interactive menu mode #"
echo "# -h | --help : Show help #"
echo "# -f | --files : Add specific files #"
echo "################################################################"
echo
}
# ---------- Default Mode ----------
Default() {
clear
echo "##########################################################"
echo "# Default Mode Started #"
echo "##########################################################"
echo
git status
pause
git add .
git status
pause
git commit -m "$DefaultCommit"
echo "Commit message: $DefaultCommit"
pause
git push
echo
echo "##########################################################"
echo "# It's Done #"
echo "##########################################################"
}
# ---------- Commit ----------
com() {
if git diff --cached --quiet; then
echo "No files staged for commit!"
pause
return
fi
git status
echo
echo "Default commit message:"
echo " $DefaultCommit"
read -p "Change it? [y/N]: " confirm
if [[ "$confirm" =~ ^[yY]$ ]]; then
read -p "Enter commit message: " msg
git commit -m "$msg"
else
git commit -m "$DefaultCommit"
fi
}
# ---------- Interactive Add ----------
InteractiveAdd() {
clear
echo "Add Files"
echo "--------------------------------"
echo "1) Add all files"
echo "2) Add modified files"
echo "3) Add untracked files"
echo "4) Select files manually"
echo "5) Back"
echo
read -p "Choose: " add_choice
case $add_choice in
1) git add . ;;
2) git add $(git ls-files -m) ;;
3) git add $(git ls-files --others --exclude-standard) ;;
4) ManualFileSelect ;;
5) return ;;
*) echo "Invalid choice"; sleep 1 ;;
esac
}
ManualFileSelect() {
files=$(git status --porcelain | awk '{print $2}')
if [ -z "$files" ]; then
echo "No files available"
pause
return
fi
echo "Select files:"
select file in $files "Done"; do
[[ $file == "Done" ]] && break
git add "$file"
echo "Added $file"
done
}
# ---------- Branch Menu ----------
BranchMenu() {
clear
echo "Branch Operations"
echo "--------------------------------"
echo "1) List branches"
echo "2) Switch branch"
echo "3) Create branch"
echo "4) Delete branch"
echo "5) Back"
echo
read -p "Choose: " bchoice
case $bchoice in
1) git branch; pause ;;
2) read -p "Branch name: " b; git checkout "$b"; pause ;;
3) read -p "New branch name: " b; git checkout -b "$b"; pause ;;
4) read -p "Delete branch name: " b; git branch -d "$b"; pause ;;
5) return ;;
esac
}
# ---------- Interactive Menu ----------
InteractiveMenu() {
while true; do
clear
echo "======================================="
echo " GitPush Interactive "
echo "======================================="
echo "1) Git Status"
echo "2) Add Files"
echo "3) Commit"
echo "4) Push"
echo "5) Pull"
echo "6) Branch Operations"
echo "7) Log"
echo "8) Exit"
echo "---------------------------------------"
read -p "Select an option [1-8]: " choice
case $choice in
1) git status; pause ;;
2) InteractiveAdd ;;
3) com ;;
4) git push; pause ;;
5) git pull; pause ;;
6) BranchMenu ;;
7) git log --oneline --decorate --graph --all | less ;;
8) exit 0 ;;
*) echo "Invalid choice"; sleep 1 ;;
esac
done
}
# ---------- Argument Handling ----------
case "$op1" in
"-i")
InteractiveMenu
;;
"-h"|"--help")
Help
;;
"")
Default
;;
*)
echo "Unknown option: $op1"
Help
;;
esac