xrsh-com/com/isoterminal/mnt/js
Leon van Kammen 69a1760a11
All checks were successful
/ mirror_to_github (push) Successful in 20s
/ test (push) Successful in 4s
improved javascript bridge
2024-08-29 15:18:14 +00:00

19 lines
592 B
Bash
Executable file

#!/bin/sh
test -z "$1" && { echo "Usage: js 'somefunction(1)'"; exit 0; }
test -n "$BROWSER" || { alert warning "/dev/browser not active (are you running outside of v86?)"; }
javascript="$*"
# if we are run as shebang, use the file as input
case "$1" in
*/*) javascript="args = String('$*').split(' '); $(cat $1 | tail +2)"
;;
esac
echo -n "$javascript" > /dev/browser/js
# should we use flock, an awesome way to make processes read/write the same file
# while preventing 1001 concurrency issues?
# attempt:
#
# flock /dev/browser/js -c "echo \"$javascript\" > /dev/browser/js"