-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwush.sh
executable file
·111 lines (89 loc) · 2.28 KB
/
wush.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
# -----
# Subroutines
# -----
function printError() {
echo -e "\e[31m$1\e[0m"
}
function highlightText() {
echo -e "\e[32m$1\e[0m"
}
function confirm() {
local valid_options=("y" "Y" "n" "N" "")
is_valid_option() {
local input=$1
for option in "${valid_options[@]}"; do
if [[ "$input" = "$option" ]]; then
return 0
fi
done
return 1
}
local user_input=-1
while ! is_valid_option "$user_input"; do
echo -n -e "$1"
read user_input
done
if [[ $user_input = '' || $user_input = "y" || $user_input = "Y" ]]; then
return 0
else
return 1
fi
}
prompt_output=''
function prompt() {
prompt_output=''
local user_input=""
while [[ $user_input = "" ]]; do
echo -n -e "$1"
read user_input
done
1=$user_input
prompt_output=$user_input
}
# ----
# Start
# ----
# Handle user inputs
cohort_id=$1
session=$2
# Interactive mode if no cohort id is provided
if [ $# -lt 1 ]; then
test
prompt "Enter cohort id (hh-test-24-1): "
cohort_id="$prompt_output"
fi
if [ "$cohort_id" = "" ]; then
echo $(printError "Error: You must provide a cohort id.")
exit 1
fi
# Interactive mode if no session name is provided
if [ $# -lt 2 ]; then
prompt "Enter session name (shell-basics): "
session="$prompt_output"
fi
if [ "$session" = '' ]; then
echo $(printError "Error: You must provide a session name.")
exit 1
fi
# Check if current folder is a git repository
if [ ! -d ".git" ]; then
if ! confirm "This directory is not a git repository. Initialize one? [Y/n]: "; then
echo $(printError "Error: This command needs to be executed in a git repository you want to upload.")
exit 1
fi
git init
fi
repository_name="$cohort_id"-"$session"
# Let user check for spelling mistakes
if ! confirm "A new remote repository $(highlightText "$repository_name") will be created. Proceed? [Y/n]: "; then
echo "Abort..."
exit 0
fi
Commit everything and upload the repository
git add . && git commit -m "initial commit"
gh repo create -s=. --push --public --remote=origin neuefische-web-demos/"$repository_name"
if [ $? -eq 0 ]; then
echo $(highlightText "Repository created: https://github.com/neuefische-web-demos/$repository_name")
else
echo $(printError "Failed to create repository. Please check if 'gh' command is installed.")
fi