As I am starting to be tired of reverse-searching in history for the C++ compile command, which I'm using - details on my flags are written here, I defined the following .bash_aliases function:
function compile-cpp {
if [ -z "$1" ]
then
{
echo "Need a file to compile as argument."
}
else
{
# extract file name from path
filename=$(basename "$1")
# cut the extension
filename="${filename%.*}"
# compile
g++ $1 -std=c++14 -Wall -Wextra -Werror -Wpedantic -pedantic-errors -o "$filename"
}
fi
}
The goal was to take one cpp file as argument and compile it under the same name as the source's.
So, e.g. when I call:
compile-cpp delete.cpp
I expect it to output a file named as:
delete
In the same directory.
No problems, so far, detected by me, but as I am a C++ beginner, I can't know for sure, if this command will more or less always work.
Note: I don't wish to use a Makefile yet. The projects and various examples I work with are so little and there's so many of them, I believe it would be counterproductive.
I found the following question, probably trying to achieve somewhat similar thing:
But since I have different demands, looking at his code, I believe it is not its duplicate, in spite of having close to the same titles.