xrsh-com/com/isoterminal/mnt/jsh
Leon van Kammen 7bfa591536
All checks were successful
/ test (push) Successful in 4s
various unix utilities to interface with browser
2024-08-27 18:40:05 +00:00

37 lines
603 B
Bash
Executable file

#!/bin/sh
# usage: jsh <function> [arg1] [arg2] ...
#
# 'jsh prompt question answer' executes: js prompt('question','answer') )
to_js(){
printf "%s(" "$1"
shift
for arg in "$@"; do
case "$arg" in
(*[\.0-9]*)
printf '%s,' "$arg"
;;
(*)
printf '"%s",' "$arg"
;;
esac
done
printf ")\n"
}
# run argument as js
test -z $1 || {
func=$(to_js "$@")
func=${func/,)/)}
js "$func"
}
# otherwise start repl
while true; do
echo -n "$(printf "\033[0m")jsh> $(printf "\033[0m")"
read input
test $input = exit && exit
js "$input"
done