Skip to content

Commit 3cf55d5

Browse files
Julian-MentastitstreamDOTh
authored andcommitted
updated runme.bh (#254)
1 parent ca157d7 commit 3cf55d5

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Make sure you adhere to the `algorithm/language/file` folder structure while add
2929
Additionally we recommend using standard convention for your language such as indentation and variable naming while writing the algorithm.
3030
Useful comments will be a help. Finally, if you can write tests for you code, we urge you to do so.
3131

32+
**Easiest way (Recommended) ⭐️ - You can run `bash runme.bh` to make the appropriate file structure.**
33+
3234
## Any contributions you make will be under the MIT License
3335
In short, when you submit code changes, your submissions are understood to be under the same MIT License
3436
that covers the project. Feel free to contact the maintainers if that's a concern.

runme.bh

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/bash
2+
3+
intro() {
4+
echo "Thank you for forking CodeZila"
5+
echo "Please input any names without any special characters"
6+
echo "For example: 'Insertion Sort' or 'Linked Lists'"
7+
read -p "What is the name of the algorithm or design you want to implement? " algorithm
8+
checkInput "$algorithm"
9+
pickLanguague "$algorithm"
10+
printTree "$algorithm" "$language"
11+
checkDir "$algorithm"
12+
}
13+
14+
# Checks the input to see if it does not have illegal characters
15+
checkInput() {
16+
# $1 is the string being checked
17+
if [[ "$1" == *['!'@\$%^\&*()_+]* ]]
18+
then
19+
echo "Illegal character used"
20+
exit
21+
fi
22+
}
23+
24+
# Asks the user that language they would like to use
25+
pickLanguague() {
26+
echo "Select the language you want to implement "$1" in?"
27+
echo "1) C++"
28+
echo "2) C"
29+
echo "3) C#"
30+
echo "4) Java"
31+
echo "5) JavaScript"
32+
echo "6) GoLang"
33+
echo "7) Python"
34+
echo "8) Ruby"
35+
echo "9) Other"
36+
read n
37+
case $n in
38+
1) language='C++';;
39+
2) language='C';;
40+
3) language='C#';;
41+
4) language='Java';;
42+
5) language='JavaScript';;
43+
6) language='GoLang';;
44+
7) language='Python';;
45+
8) language='Ruby';;
46+
9) inputLanguage "$1";;
47+
*) echo "Error" ; exit;;
48+
esac
49+
50+
createDir "$1" "$language"
51+
}
52+
53+
inputLanguage() {
54+
read -p "What language do you want to implement '$1' in? " lang
55+
checkInput "$lang"
56+
createDir "$1" "$lang"
57+
printTree "$1" "$lang"
58+
checkDir
59+
exit
60+
}
61+
62+
# Shows the user the created file structure
63+
printTree() {
64+
echo "$1"
65+
echo "├── readme.md"
66+
echo "└── $2"
67+
}
68+
69+
# Creates the file structure
70+
createDir() {
71+
if [ ! -d "$1" ]
72+
then
73+
mkdir "$1"
74+
fi
75+
76+
if [ ! -d "$1/$2" ]
77+
then
78+
mkdir "$1"/$2
79+
fi
80+
createReadme "$1" "$2"
81+
}
82+
83+
createReadme() {
84+
if [ -e "$1"/"$2"/readme.md ]
85+
then
86+
echo "readme file already exists for '$1/$2'"
87+
else
88+
read -p "Do you want to create a Readme (y/n)? " response
89+
case "$response" in
90+
y|Y ) echo "# $1 implemented in $2" > "$1"/"$2"/readme.md;;
91+
n|N ) ;;
92+
* ) echo "Readme not created" ;;
93+
esac
94+
fi
95+
}
96+
97+
# Asks the user if they want to keep the files
98+
checkDir() {
99+
read -p "Is the file structure above correct? (y/n)? " choice
100+
case "$choice" in
101+
y|Y ) echo "Enjoy Coding!";;
102+
n|N ) echo "Files Deleted"; rm -rf $1 ;;
103+
* ) echo "invalid - Files not deleted";;
104+
esac
105+
}
106+
107+
intro

0 commit comments

Comments
 (0)