-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.sh
executable file
·56 lines (45 loc) · 1.14 KB
/
submit.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
#!/bin/bash
read -p "Please enter the name/url of the Kata: " input
# Attempt to get interpret user input as a URL
websiteName=$(curl -skm 15 "$(echo $input | sed 's/train\/.*//')" | grep -oP '<meta content="\K[^"]*(?=" property="og:title" />)')
if [[ "$websiteName" ]]; then
input="$websiteName"
fi
name=$(echo "${input,,}" | xargs | sed -r "s/[^a-z0-9]+/-/g" | sed -r "s/^-|-$//g")
if [[ ! "$name" || "$name" == "https-www-"* || "$name" == "http-www-"* ]]; then
echo "Bad input"
exit 1
fi
read -p "Please enter language used for '$name': " ext
case $ext in
py*)
ext=(py python)
;;
c++|cpp)
ext=(cpp cpp)
;;
c|go|java)
ext=($ext $ext)
;;
bash|shell|sh)
ext=(sh shell)
;;
*)
echo "Invalid / new language"
exit 2
;;
esac
cd ${ext[1]}
# Make directories
mkdir -p "$name"
cd "$name"
if [[ -f "$name.$ext" ]]; then
mkdir -p backup
mv --backup=numbered "$name.$ext" "backup/$name.$ext"
fi
vim "$name.$ext"
echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=https://www.codewars.com/kata/$name/${ext[1]}\" /></head></html>" > "link.html"
git pull
git add --all
git commit -m "Completed '$name' challenge"
git push