-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzer.sh
executable file
·111 lines (98 loc) · 3.18 KB
/
fizzer.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
#!/bin/bash
list() {
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Formatting
BOLD=$(tput bold)
RESET=$(tput sgr0)
printf "${BOLD}${GREEN}%-20s %-20s${RESET}\n" "Name" "Author"
printf "${BOLD}${GREEN}%-20s %-20s${RESET}\n" "----" "------"
for dir in $(ls -d */); do
if [ -f "$dir"*.fbc ]; then
file=$(ls $dir*.fbc)
name=$(grep -o '^name=.*' $file | cut -d'=' -f2)
author=$(grep -o '^author=.*' $file | cut -d'=' -f2)
printf "${BOLD}${CYAN}%-20s %-20s${RESET}\n" "$name" "$author"
fi
done
}
run() {
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Formatting
BOLD=$(tput bold)
RESET=$(tput sgr0)
if [ -d "$1" ]; then
if [ -z "$(ls -A $1/*.fbc 2>/dev/null)" ]; then
echo -e "${RED}No .fbc file found in the directory.${NC}"
echo -e "${RED}Please provide a valid directory with .fbc file.${NC}"
return
fi
file=$(ls $1/*.fbc)
run_command=$(grep -o '^run=.*' $file | cut -d'=' -f2)
if [ -z "$run_command" ]; then
echo -e "${RED}No run command found in the .fbc file.${NC}"
echo -e "${RED}Please provide a valid run command.${NC}"
return
fi
cd $1
run_command=${run_command//<arg>/$2}
echo -e "${GREEN}Now running: $run_command${NC}"
eval $run_command
cd ..
else
echo -e "${RED}That directory does not exist.${NC}"
echo -e "${RED}Please write the name of the directory you would like to run.${NC}"
fi
}
help() {
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Formatting
BOLD=$(tput bold)
ITALIC=$(tput sitm)
UNDERLINE=$(tput smul)
RESET=$(tput sgr0)
echo -e "${BOLD}Help:${RESET} This script can take one of 3 arguments [ ${GREEN}list${RESET} | ${GREEN}run${RESET} | ${GREEN}help${RESET} ]"
echo
echo -e "${BOLD}Usage:${RESET}"
echo -e " ${GREEN}list:${RESET} List all the FizzBuzz files in the current directory and their authors."
echo -e " ${ITALIC}Example:${RESET} ./fizzer.sh list"
echo
echo -e " ${GREEN}run:${RESET} Run a FizzBuzz file in a specified directory with an optional argument."
echo -e " ${ITALIC}Example:${RESET} ./fizzer.sh run <directory> <argument>"
echo
echo -e "${BOLD}Project Information:${RESET}"
echo -e " ${GREEN}GitHub:${RESET} https://github.com/jotrorox/fizzbuzz"
echo -e " ${GREEN}Author:${RESET} Johannes (Jotrorox)"
echo -e " ${GREEN}Email:${RESET} [email protected]"
echo -e " ${GREEN}Website:${RESET} https://jotrorox.com"
echo -e " ${GREEN}Version:${RESET} 1.0"
echo -e " ${GREEN}License:${RESET} AGPLv3"
echo
}
if [ "$1" == "list" ]; then
list
elif [ "$1" == "run" ]; then
run $2 $3
else
help
fi