-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu_to_github.sh
More file actions
163 lines (122 loc) · 3.1 KB
/
menu_to_github.sh
File metadata and controls
163 lines (122 loc) · 3.1 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
#!/usr/bin/env bash
set -euo pipefail
git_add() {
# Updated the script to add all files
# Created to automate git add, commit, pull, and push
# List all files in current directory (excluding .git)
echo "Files in current directory:"
mapfile -t files < <(find . -maxdepth 1 -type f ! -name ".git*" -printf "%f\n")
# If no files found
if [[ ${#files[@]} -eq 0 ]]; then
echo "No files found in this directory."
exit 1
fi
# Display files with numbers
for i in "${!files[@]}"; do
echo "$((i+1)). ${files[$i]}"
done
echo ". -> Add all files"
# Ask user to pick a file or add all
read -r -p "Select the file number you want to upload (or '.' for all files): " choice
# Detect current branch automatically
branch="$(git branch --show-current)"
if ! git rev-parse --abbrev-ref --symbolic-full-name "@{u}" >/dev/null 2>&1; then
echo "No upstream set for $branch."
echo "Set one with: git push -u origin $branch"
exit 1
fi
# Ask for commit message
read -r -p "Enter commit message: " commit_msg
# Pull latest changes
echo "Pulling latest changes from remote..."
git pull origin "$branch"
# Stage files
if [[ "$choice" == "." ]]; then
git add .
echo "All files staged."
else
# Validate input
if ! [[ "$choice" =~ ^[0-9]+$ ]] || (( choice < 1 || choice > ${#files[@]} )); then
echo "Invalid choice."
exit 1
fi
filename="${files[$((choice-1))]}"
git add "$filename"
echo "Staged file: $filename"
fi
# Commit and push
git commit -m "$commit_msg"
git push origin "$branch"
echo "Changes successfully committed and pushed to '$branch'!"
}
git_delete() {
#-------------------------------------------------
# THIS SCRIPT WILL DELETE YOUR FILES AND REMOVE IT
# i CREATED A PROMPT TO ASK BEFORE DELETEING
set -euo pipefail
read -rp "File or folder to delete: " TARGET
if [[ -z "$TARGET" ]]; then
echo "Nothing entered."
return 1
fi
if [[ ! -e "$TARGET" ]]; then
echo "Target does not exist: $TARGET"
return 1
fi
read -rp "Commit message: " MSG
if [[ -z "$MSG" ]]; then
echo "Commit message required."
return 1
fi
echo
echo "WARNING"
echo "You are about to PERMANENTLY remove this from Git and GitHub:"
echo
echo " $TARGET"
echo
echo "This WILL delete the file/folder locally."
echo "This CANNOT be undone easily."
echo "type anything in the console to abort."
echo
echo "Type exactly:"
echo "i want to delete this"
echo
read -r CONFIRM
if [[ "$CONFIRM" != "i want to delete this" ]]; then
echo "Aborted."
return 1
fi
git rm -r "$TARGET"
git commit -m "$MSG"
git push
echo "Removed and pushed: $TARGET"
}
git_check() {
git branch
read -rp "Enter branch to switch: " branch
if git show-ref --verify --quiet "refs/heads/$branch"; then
git switch "$branch"
else
echo "Branch does not exist, try again."
fi
}
MENU="
GITHUB MENU
1) check branch and switch to it
2) Add files to github
3) Delete a file/dir off github
q) Quit
"
echo "$MENU"
read -rp "Select option: " choice
if [[ "$choice" == "1" ]]; then
git_check
elif [[ "$choice" == "2" ]]; then
git_add
elif [[ "$choice" == "3" ]]; then
git_delete
elif [[ "$choice" == "q" ]]; then
exit 0
else
echo "Invalid option"
fi