Specify the currently open file as entrypoint in .replit

When I have a collection of multiple scripts in a Replit project, I would like to run the script I have currently open in the Replit editor. So something like you can do in VS Code where you can specify the launch task for the current file.

I know that I can always manually edit the .replit file and enter the desired path as entrypoint, but some configuration to automatically run the currently open file would be cool.

2 Likes

I don’t think this exists and I think it would be a good feature request.

1 Like

Welcome to the community! @sonicx180

I’ve moved this topic to #feature-requests as this doesn’t seem to be a feature yet.

2 Likes

Add/change in the start of the .replit file (replace *.py with the glob of the files you want to run):

onBoot = 'for i in *.py; do ((/nix/store/fbi9r30p3lqk96lmw5b1v1bpbj62cr2l-inotify-tools-3.20.11.0/bin/inotifywait -e modify $i;sed -i "/entrypoint/s/\".*\"/\"$i\"/" .replit)&);done'
3 Likes

improved: add/change to start of .replit:

onBoot = '''/nix/store/fbi9r30p3lqk96lmw5b1v1bpbj62cr2l-inotify-tools-3.20.11.0/bin/inotifywait -rqme create --format=%f%w --include='\..+\.py.[0-9]+~' .|while
read f
do
f=${f#.}
o=
r=
while
read -r l||[ "$l" ]
do
case $r
in
"")case $l
in entrypoint*)m="${l%\"*\"}\"${f#*~./}${f%.*~*}\""
case $m
in
"$l")break
esac
l=$m
r=1
esac
esac
o="$o$l
"
false
done<.replit||echo -n "$o">.replit
done'''

And run kill 1 in Shell.
This will map the entrypoint to the last file you edited through the IDE.
Replace .+\.py on line 1 with the ERE of the files you want to be auto-set as entrypoint.
(I tried an option which checks for you just visiting the file in the editor but I found that that’s impossible. Maybe you can do this with an extension)

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.