-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim_run_script.sh
executable file
·176 lines (161 loc) · 5.05 KB
/
vim_run_script.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
#Author: Arafat Hasan<opendoor.arafat[at]gmail[dot]com>
#
# ___ ___ ___ ___
# / /\ / /\ /__/\ ___ /__/\
# / /:/ / /:/_ \ \:\ / /\ \ \:\
# /__/::\ / /:/ /\ \ \:\ / /:/ \ \:\
# \__\/\:\ / /:/ /:/_ _____\__\:\ /__/::\ _____\__\:\
# \ \:\ /__/:/ /:/ /\ /__/::::::::\ \__\/\:\__ /__/::::::::\
# \__\:\ \ \:\/:/ /:/ \ \:\~~\~~\/ \ \:\/\ \ \:\~~\~~\/
# / /:/ \ \::/ /:/ \ \:\ ~~~ \__\::/ \ \:\ ~~~
# /__/:/ \ \:\/:/ \ \:\ /__/:/ \ \:\
# \__\/ \ \::/ \ \:\ \__\/ \ \:\
# \__\/ \__\/ \__\/
#
filename=$(basename "$2")
filenameWithPath=$2
filename_without_ex=${filename%.*}
#filename_ex="${filename%.*}"
extension=${filename##*.}
if [ "$1" == "stdio" ]
then
start=$(date +%s.%N)
if [ "$extension" == "c" ] || [ "$extension" == "cpp" ]
then
./a.out
elif [ "$extension" == "java" ]
then
java Main
#java $filename_without_ex
elif [ "$extension" == "py" ]
then
python3 $filenameWithPath
elif [ "$extension" == "sh" ]
then
bash $filenameWithPath
else
echo "File Format Not Recognized [in run-script]"
fi
return=$?
dur=$(echo "$(date +%s.%N) - $start" | bc)
echo
echo "--------------------------------"
echo "Program exited with code: $return"
printf "Execution time: %.6f seconds" $dur
echo
#echo "What's about Jenin? :-)"
echo "Press return to continue..."
dummy_var=""
read dummy_var
elif [ "$1" == "i" ]
then
#echo
#echo "==============================================="
#echo "Input from input.txt and write output to stdout"
#echo "==============================================="
start=$(date +%s.%N)
if [ "$extension" == "c" ] || [ "$extension" == "cpp" ]
then
./a.out < input.txt
elif [ "$extension" == "java" ]
then
java Main < input.txt
#java $filename_without_ex < input.txt
elif [ "$extension" == "py" ]
then
python3 $filenameWithPath < input.txt
elif [ "$extension" == "sh" ]
then
bash $filenameWithPath < input.txt
else
echo "File Format Not Recognized [in run-script]"
fi
return=$?
dur=$(echo "$(date +%s.%N) - $start" | bc)
echo
echo "--------------------------------"
echo "Program exited with code: $return"
printf "Execution time: %.6f seconds" $dur
echo
#echo "What's about Jenin? :-)"
echo "Press return to continue..."
dummy_var=""
read dummy_var
elif [ "$1" == "io" ]
then
echo
#echo "==================================================="
echo "Input from input.txt and write output to output.txt"
#echo "==================================================="
echo "Running..."
start=$(date +%s.%N)
if [ "$extension" == "c" ] || [ "$extension" == "cpp" ]
then
./a.out < input.txt > output.txt
elif [ "$extension" == "java" ]
then
java Main < input.txt > output.txt
#java $filename_without_ex < input.txt > output.txt
elif [ "$extension" == "py" ]
then
python3 $filenameWithPath < input.txt > output.txt
elif [ "$extension" == "sh" ]
then
bash $filenameWithPath < input.txt > output.txt
else
echo "File Format Not Recognized [in run-script]"
fi
return=$?
dur=$(echo "$(date +%s.%N) - $start" | bc)
echo
echo "Completed"
echo
echo "--------------------------------"
echo "Program exited with code: $return"
printf "Execution time: %.6f seconds" $dur
echo
#echo "What's about Jenin? :-)"
echo "Press return to continue..."
dummy_var=""
read dummy_var
elif [ "$1" == "compile-build" ]
then
echo
g++ -g -Wall -Wextra -Wshadow -Wfloat-equal -pedantic -std=c++17 -O2 -Wformat=2 -Wconversion -Wno-sign-conversion -lm "$2"
return=$?
if [ $return -eq 0 ]
then
echo "----------------------------------------------"
echo "Compilation and building finished successfully"
else
echo "----------------------------------"
echo "Error occurred, compilation failed"
fi
echo
elif [ "$1" == "compile" ]
then
echo
if [ "$extension" == "cpp" ]
then
g++ -c -g -Wall -Wextra -Wshadow -Wfloat-equal -pedantic -std=c++17 -O2 -Wformat=2 -Wconversion -Wno-sign-conversion -lm "$2"
elif [ "$extension" == "c" ]
then
gcc -c -g -Wall -Wextra -Wshadow -Wfloat-equal -pedantic -std=c++17 -O2 -Wformat=2 -Wconversion -Wno-sign-conversion -lm "$2"
elif [ "$extension" == "java" ]
then
javac -d /media/Softwares/Programming "$2"
fi
return=$?
if [ $return -eq 0 ]
then
echo "---------------------------------"
echo "Compilation finished successfully"
else
echo "----------------------------------"
echo "Error occurred, compilation failed"
fi
echo
else
echo "vim_run_script ERROR"
fi