From fcce1c25e13b82edb9a254bb6b6e0df0d69d72ad Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 8 Feb 2023 11:47:11 +0100 Subject: [PATCH] initial commit - addded claunch and while-curl --- claunch.sh | 110 +++++++++++++++++++++++++++++++++++++++++++++++ git-auto-push.sh | 3 ++ test.cpp | 8 ++++ while-curl.sh | 24 +++++++++++ 4 files changed, 145 insertions(+) create mode 100755 claunch.sh create mode 100644 git-auto-push.sh create mode 100644 test.cpp create mode 100755 while-curl.sh diff --git a/claunch.sh b/claunch.sh new file mode 100755 index 0000000..5ef8f3c --- /dev/null +++ b/claunch.sh @@ -0,0 +1,110 @@ +# A simple script that takes a cpp file as an argument, compiles it and if sucsessful runs the compiled code. +#option flag to delete compiled file after completion +#option flag to choose compiled file directory +#option flag to choose g++ or gcc +#option flag to pass arguments to compiler +#help menu + + + +#initial argument parsing +if [ $# -eq 0 ]; then + echo "No arguments supplied try -h or --help for how to use" + exit 1 +fi +if [ $1 = "-h" ] || [ $1 = "--help" ]; then + echo "help menu" + echo "claunch takes a cpp/c file as an argument, compiles it and if sucsessful runs the compiled code." + echo "-f --force option flag to force the program to run, even if it writes over stuff" + echo "-r --remove option flag to delete compiled file after completion" + echo "-d --dir option flag to choose compiled file directory" + echo "-c --gcc option flag to choose gcc over the default g++" + echo "-a --args option flag to pass arguments to compiler" + echo "-h --help this help menu" + exit 0 +fi + +#initializing variables +force=false +remove=false +dir="." +gcc=false +args="" + +#argument parsing +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -f|--force) + force=true + shift # past argument + ;; + -r|--remove) + remove=true + shift # past argument + ;; + -d|--dir) + dir="$2" + shift # past argument + shift # past value + ;; + -c|--gcc) + gcc=true + shift # past argument + ;; + -a|--args) + args="$2" + shift # past argument + shift # past value + ;; + *) + file="$1" + shift # past argument + ;; +esac +done + +#checking if compiled file is there before and abort unless force is enabled +if [ -f "$dir/${file%.*}" ]; then + if [ $force = false ]; then + echo "compiled file already exists, use -f or --force to run anyway" + exit 1 + fi +fi + + + +#checking if file is cpp or c +if [ ${file: -4} == ".cpp" ]; then + if [ $gcc = false ]; then + g++ $args $file -o "$dir/${file%.*}" + if [ $? -eq 0 ]; then + "$dir/${file%.*}" + if [ $remove = true ]; then + rm "$dir/${file%.*}" + fi + fi + else + gcc $args $file -o "$dir/${file%.*}" + if [ $? -eq 0 ]; then + "$dir/${file%.*}" + if [ $remove = true ]; then + rm "$dir/${file%.*}" + fi + fi + fi +elif [ ${file: -2} == ".c" ]; then + gcc $args $file -o "$dir/${file%.*}" + if [ $? -eq 0 ]; then + "$dir/${file%.*}" + if [ $remove = true ]; then + rm "$dir/${file%.*}" + fi + fi +else + echo "file is not a cpp or c file" + exit 1 +fi + diff --git a/git-auto-push.sh b/git-auto-push.sh new file mode 100644 index 0000000..6494500 --- /dev/null +++ b/git-auto-push.sh @@ -0,0 +1,3 @@ +#stages all files in current or given folder, and commits with an automated message before pushing to auto or given server branch + +##TODO:implement diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..2988c0f --- /dev/null +++ b/test.cpp @@ -0,0 +1,8 @@ +//helloworld +#include +using namespace std; +int main() +{ +cout << "Hello World!" << endl; +return 0; +} diff --git a/while-curl.sh b/while-curl.sh new file mode 100755 index 0000000..57c11db --- /dev/null +++ b/while-curl.sh @@ -0,0 +1,24 @@ +#used by me for basic network and api resillient testing + +#take inputs +echo "Enter the url to curl: " +read url +echo "Enter the number of times to curl, or 0 for forever: " +read num +echo "Enter the time between curls in seconds: " +read time + +#run curl +if [ $num -ne 0 ]; then + for ((i=1;i<=$num;i++)) + do + curl $url + sleep $time + done +else + while true + do + curl $url + sleep $time + done +fi \ No newline at end of file