xrsh-com/com/isoterminal/mnt/jsh

38 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