|
| 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