xrsh-com/com/isoterminal/mnt/jsh

45 lines
785 B
Plaintext
Raw Normal View History

#!/bin/sh
# usage: jsh <function> [arg1] [arg2] ...
#
# 'jsh prompt question answer' executes: js prompt('question','answer') )
2024-09-02 15:05:47 +02:00
source /mnt/profile.sh
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
2024-08-29 17:18:14 +02:00
test -z "$1" || {
func=$(to_js "$@")
func=${func/,)/)}
js "$func"
2024-08-29 17:18:14 +02:00
hook "$@"
exit 0
}
# otherwise start repl
2024-08-29 17:18:14 +02:00
echo "jsh> type 'exit' or CTRL-C to quit"
echo "jsh> HINT: to run alert('foo') outside this REPL, run 'jsh alert foo'"
echo "jsh>"
while true; do
2024-08-29 17:18:14 +02:00
echo -n -e "\r$(printf "\033[0m")jsh> $(printf "\033[0m")"
read line
test "$line" = exit && exit
js "$line"
done