Skip to content

Instantly share code, notes, and snippets.

@SharafatKarim
Last active May 15, 2023 00:48
Show Gist options
  • Save SharafatKarim/30a70ad14e265c6aba8af4e87ef6b2cf to your computer and use it in GitHub Desktop.
Save SharafatKarim/30a70ad14e265c6aba8af4e87ef6b2cf to your computer and use it in GitHub Desktop.
# sharafat specials
# bash script to automate running a single c file
#
# to use, just put those lines in your bashrc/ zshrc,
# restart your shell or source from bashrc/ zshrc
# in any directory you can just type
# cl file_path/file_name.cpp
#
# (c file compile and run and then delete the compiled binary, all in one)
# it should work out of the box for c and c++
function cl()
{
echo -e "compiling ${1%.*}"
# time gcc -lstdc++ -lm -o ${1%.*} $1
time g++ -o ${1%.*} $1
if [ -f ${1%.*} ]
then
echo -e "----------------- \n"
chmod +x ${1%.*}
./${1%.*}
rm ${1%.*}
else
echo -e "----------------- \n"
echo -e "compiler didn't create an executable file!\n"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment