Skip to content

Instantly share code, notes, and snippets.

@RyanTheTechMan
Last active November 25, 2022 06:40
Show Gist options
  • Save RyanTheTechMan/d4de40cfc797dfa168df8ac2583ee9c4 to your computer and use it in GitHub Desktop.
Save RyanTheTechMan/d4de40cfc797dfa168df8ac2583ee9c4 to your computer and use it in GitHub Desktop.
A script that adds commands that make c++ development faster! Add this file to your .bashrc to use them.
#!/bin/bash
function qrun() {
if (( $# == 0 )); then
echo "Usage: qrun [filename] <-k (keep)>"
return 1
else
g++ -c $1.cc;g++ $1.o -o $1;./$1 "${@:2}"
if (( $# == 2 )); then
if [[ $2 == "-k" ]]; then
echo "[QRUN] Keeping files"
else
echo "[QRUN] Removing files"
rm $1.o $1
fi
else
echo "[QRUN] Removing files"
rm $1.o $1
fi
fi
}
function qmake() {
printMake=false
if (( $# == 0 )); then
echo "Usage: qmake <-m make_file_function> [filename]"
return 1
else
if (( $2 == "-m" )); then
if (( $# >= 3 )); then
(make $2) 2>&1 | tee ~/qmake_temp
clear
if test -f "./$3"; then
./"${@:3}"
else
echo "[QMAKE] ❌ Error running. File was not found! ❌"
printMake=true
fi
else
echo "Usage: qmake <-m make_file_function> [filename]"
return 1
fi
else
(make) 2>&1 | tee ~/qmake_temp
clear
if test -f "./$1"; then
./"${@:1}"
else
echo "[QMAKE] ❌ Error running. File was not found! ❌"
printMake=true
fi
fi
fi
qmake_temp=$(< ~/qmake_temp)
if [[ "$qmake_temp" =~ ^(.*up to date\.)$ ]]; then
if [[ $printMake == false ]]; then
echo "[QMAKE] ⚠️ No changes made. Did not recompile. ⚠️"
fi
elif [[ "$qmake_temp" =~ ^(.*Stop\.)$ || "$qmake_temp" =~ ^(.*Error 1)$ ]]; then
echo "[QMAKE] ❌ Error compiling. Did not recompile! ❌"
printMake=true
else
echo "[QMAKE] ✅ Successfully compiled! ✅"
fi
if [[ $printMake == true ]]; then
echo "[QMAKE] 📜 ↓↓↓↓↓ Make Output ↓↓↓↓↓ 📜"
echo $qmake_temp
echo "[QMAKE] 📜 ↑↑↑↑↑ Make Output ↑↑↑↑↑ 📜"
fi
rm ~/qmake_temp
}
function qclass() {
if (( $# == 0 )); then
echo "[QCLASS] Makes a '.cc' and '.h' of the file name. Usage: qclass [filename]"
return 1
else
if test -f "$1.cc" || test -f "$1.h"; then
echo "[QCLASS] ❌ Error. File(s) already exists! ❌"
return 1
fi
id=${1^^}
touch $1.cc $1.h
echo "#include \"$1.h\"" >> $1.cc
echo "#ifndef INCLUDED_$id" >> $1.h
echo "#define INCLUDED_$id" >> $1.h
echo "" >> $1.h
echo "" >> $1.h
echo "#endif" >> $1.h
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment