1
\$\begingroup\$

It's a pretty simple script really, i just want to know if there is a way to improve it.

#!/bin/env sh

set -o nounset
set -o errexit

if [[ "$#" -ne 3 ]] && [[ "$#" -ne 2 ]];
then
    echo "Usage: ./project.sh [NAME] [GENERATOR] [MAKEFILES]"
    exit 1
fi


mkdir $HOME/Dev/$1
mkdir $HOME/Dev/$1/src/
mkdir $HOME/Dev/$1/build/
cp $HOME/ProjectSetup/CMakeLists.txt $HOME/Dev/$1/

sed -i "s/set(CMAKE_PROJECT_NAME placeholder/set(CMAKE_PROJECT_NAME $1/" $HOME/Dev/$1/CMakeLists.txt

git init $HOME/Dev/$1/
cat > $HOME/Dev/$1/.gitignore << EOL
build/
compile_commands.json
.vscode/
EOL

touch $HOME/Dev/$1/src/main.cpp
cat > $HOME/Dev/$1/src/main.cpp << EOL 

int main(int argc, const char* argv[])
{

    return 0;
}
EOL

if [[ "$#" -eq 3 ]];
then
    cmake -G "$2 - $3" -S $HOME/Dev/$1 -B $HOME/Dev/$1/build/ -DCMAKE_EXPORT_COMPILE_COMMANDS=1
else
    cmake -G "$2" -S $HOME/Dev/$1 -B $HOME/Dev/$1/build/ -DCMAKE_EXPORT_COMPILE_COMMANDS=1
fi
ln -s $HOME/Dev/$1/build/compile_commands.json $HOME/Dev/$1/

```
\$\endgroup\$
  • \$\begingroup\$ Hi Nadpher. Are you aiming for a generic Bourne-compatible shell or specifically bash? Your shebang line says generic shell, but your question tag says bash. So there seems to be some ambiguity over this. \$\endgroup\$ – chicks May 28 at 12:38
  • 1
    \$\begingroup\$ Yeah that's because i got the tag wrong, sorry. really i meant to write shell cause i use zsh personally. \$\endgroup\$ – Nadpher May 28 at 20:12
  • 1
    \$\begingroup\$ Thanks. I can see a few things that would get picked up by shellcheck.net \$\endgroup\$ – chicks May 29 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.