2024-08-26 12:02:35 +02:00
|
|
|
#!/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
|
2024-08-27 20:40:05 +02:00
|
|
|
case "$arg" in
|
|
|
|
(*[\.0-9]*)
|
|
|
|
printf '%s,' "$arg"
|
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
printf '"%s",' "$arg"
|
|
|
|
;;
|
|
|
|
esac
|
2024-08-26 12:02:35 +02:00
|
|
|
done
|
|
|
|
printf ")\n"
|
|
|
|
}
|
|
|
|
|
2024-08-27 20:40:05 +02:00
|
|
|
# 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
|
|
|
|
|
|
|
|
|