#!/bin/bash
faStabilo='\033[7m'
fcRouge='\033[31m'
fcJaune='\033[33;1m'
fcCyan='\033[36m'
fcGreen='\033[32m'
#-------------------------------------------------------------------
# ccontrôle si projet nim
#-------------------------------------------------------------------
if [[ ! "$2" =~ '.nim' ]]; then
echo -en $faStabilo$fcJaune"$2 -->"$faStabilo$fcRouge"ce n'est pas un fichier .nim \033[0;0m\\n"
exit 0
fi
mode=$1
projet_src=$2
projet_bin=${projet_src%.*}
#-------------------------------------------------------------------
# clean
#-------------------------------------------------------------------
if test -f $projet_bin ; then
rm -f $projet_bin
fi
if test -f $projet_bin ; then
rm -r /home/soleil/.cache/nim/$projet_bin*
fi
#-------------------------------------------------------------------
# compile
#-------------------------------------------------------------------
# force full option gtk
# debug
# nim c --threads --passc:-flto --deadCodeElim:on -d:danger -d:forceGtk -o:$projet_bin $projet_src
# prod
# nim c --verbosity:0 --hints:off --opt:size --threads --opt:size --deadCodeElim:on --warning[UnusedImport]:off -d:danger -d:forceGtk -d:release -o:$projet_bin $projet_src
# --passL:-no-pie bin executable par defaut -pie compilateur gcc and nim
if [ "$mode" == "DEBUG" ] ; then
nim c -f --deadCodeElim:on --app:GUI --passL:-no-pie -o:$projet_bin $projet_src
fi
if [ "$mode" == "PROD" ] ; then
nim c --verbosity:0 --hints:off --warning[UnusedImport]:off --deadCodeElim:on --opt:size --app:GUI --passL:-no-pie --opt:size -d:release -f -o:$projet_bin $projet_src
fi
if [ "$mode" == "TEST" ] ; then
nim c -f --deadCodeElim:on --passL:-no-pie -o:$projet_bin $projet_src
fi
#-------------------------------------------------------------------
# resultat
#-------------------------------------------------------------------
echo -en '\033[0;0m' # video normal
echo " "
if test -f "$projet_bin"; then
echo -en $faStabilo$fcCyan"BUILD "$mode"\033[0;0m "$fcJaune$projet_src"->\033[0;0m "$fcGreen $projet_bin "\033[0;0m"
echo -en " size : "
ls -lrtsh $projet_bin | cut -d " " -f6
else
echo -en $faStabilo$fcCyan"BUILD "$mode"\033[0;0m "$fcJaune$projet_src"->\033[0;0m "$faStabilo$fcRouge"not compile\033[0;0m\n"
fi
echo " "
if [ "$mode" == "TEST" ] ; then
if test -f "$projet_bin"; then
echo "..TEST.. "
echo " "
./$projet_bin
echo " "
fi
fi
exit
example Linux file compile.sh and vscode use plugin "Run Terminal Command"
If you have all the files in the same vscode workspace folder,
then you could name your 'main' nim file you want to always run, main.nim
and set a global coderunner custom command (Ctrl-Alt-K)) in settings.json.
My pc with nim on it is dead atm so I can't check or test it, but my laptop has this lua setting with which you should be able to tweak the path and file extension to work on nim:
"code-runner.customCommand": "/usr/local/bin/lua ${workspaceFolder} main.lua"
I mapped the normal command (Ctrl-Alt-N) to F8 and the custom command to F9, so I can be editing a non-main file and still run either it or the main.lua file.
The variables reference for vscode is here if you need further tweaking: https://code.visualstudio.com/docs/editor/variables-reference
You can also set up multiple commented-out custom commands for different languages and uncomment them to switch language.
Tested this working today in settings.json:
"code-runner.customCommand": "nim c -r --verbosity:0 --hints:off main.nim",
${workspaceFolder} throws an error in Nim for some reason, but you don't need it..