[Feature] Flag to run the script in a /tmp folder
It is the same stuff for https://github.com/Ph0enixKM/Amber/issues/219 or https://github.com/Ph0enixKM/Amber/issues/223
The idea is to have a flag that you put on top of the Amber script that automatically with mktemp -d create a temporary folder and move the PWD/CWD to that.
a few years ago, I used a preprocessor written in PHP for my bash script. It was used to replace keywords with code snippets. i think a similar system can be used especially for this
for example : #[execute_in_temp_folder] replaced by unsafe $mktemp -d$
in my preprocessor the use was mainly for dependencies, this could solve dependency checker
for example : #[depends:dialog/dialog] replaced by unsafe $if ! [ -x "\$(command -v dialog)" ];then echo \$"dialog command could not be found, install package dialog";exit 1; fi;$
and many other..
all my snippets were stored in a file, one file by snippet
Yes can be an attribute, for the dependency there is another ticket https://github.com/Ph0enixKM/Amber/issues/95
what is exactly the point of this feature though?
Usually scripts run in a folder dedicated so they don't mess with the system. Like file editing and so on, the idea is to have like a sandbox generated automatically and the cwd/pwd.
Can you provide a meaningful use case for this feature @Mte90 ?
This is as example on of my scripts that I use everyday:
killall vlc
rm /tmp/cvlc.sh
list=$(echo "$1" | sed -e 's/\/media/\"\/media/g' )
list=$(echo "$list" | sed -e 's/ \"/\" \"/g' )
list+='"'
echo "#!/usr/bin/env bash" > /tmp/cvlc.sh
echo "cvlc $list" >> /tmp/cvlc.sh
chmod +x /tmp/cvlc.sh
/tmp/cvlc.sh
Basically create a bash script to run and after that it will be removed, this run a folder with mp3 to my vlc in cli mode. Having a folder in /tmp generated automatically and where the script will run, it means that there are less problems that can create issues to my machine.
Maybe we can create a builtin or an attribute for this? @Ph0enixKM what do you think?
In this way we can work also on https://github.com/amber-lang/amber/issues/329