-
Notifications
You must be signed in to change notification settings - Fork 0
/
runc.sh
executable file
·26 lines (23 loc) · 916 Bytes
/
runc.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
#!/bin/bash
# run `source runc.sh` and then use this funcion anywhere
runc() {
local file_location=$1
local file_type=$(echo $file_location | sed "s/.*\.\(.*\)/\1/" | sed "s/p/+/g") # `c` or `c++`
local file_name=${1:t}
local file_directory=${1:h}
local exe_file_name=${file_name:r}
# if the file compiles without any errors this will run
local run() {
# if executables directory does not exist
if [[ $(ls $file_directory/ | grep -i -o "executables") == "" ]] then;
mkdir $file_directory/executables &&
echo "New directory created $file_directory/executables"
fi
mv ./a.out ./executables/$exe_file_name
echo "" # printing new lines
./executables/$exe_file_name $@
echo ""
}
echo "g++ $file_location -x $file_type && run $@"
g++ $file_location -x $file_type && run $@
}