Amber icon indicating copy to clipboard operation
Amber copied to clipboard

[Feature] Flag to run the script in a /tmp folder

Open Mte90 opened this issue 1 year ago • 6 comments

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.

Mte90 avatar Jun 26 '24 08:06 Mte90

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

CymDeveloppement avatar Jun 26 '24 12:06 CymDeveloppement

Yes can be an attribute, for the dependency there is another ticket https://github.com/Ph0enixKM/Amber/issues/95

Mte90 avatar Jun 26 '24 12:06 Mte90

what is exactly the point of this feature though?

b1ek avatar Jun 28 '24 11:06 b1ek

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.

Mte90 avatar Jun 28 '24 12:06 Mte90

Can you provide a meaningful use case for this feature @Mte90 ?

Ph0enixKM avatar Jul 01 '24 12:07 Ph0enixKM

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.

Mte90 avatar Jul 01 '24 12:07 Mte90

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

Mte90 avatar Dec 11 '25 11:12 Mte90