-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrcshell.sh
More file actions
executable file
·39 lines (30 loc) · 853 Bytes
/
rcshell.sh
File metadata and controls
executable file
·39 lines (30 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
# A simple repl shell for Engineer Man's Piston API.
function cleanup(){
[[ -f /tmp/data.json ]] && rm /tmp/data.json
printf "\n"
exit
}
trap cleanup SIGINT
piston_api_url="https://emkc.org/api/v1/piston/execute"
# Repl = tight while loop.
function main(){
while true; do
echo -n "piston-shell> "
read -r cmd
case $cmd in
exit|quit|q)
cleanup;;
esac
# Escape double quotes.
cmd=$(sed 's/"/\\"/g' <<< $cmd)
echo "{\"language\":\"bash\", \"source\":\"$cmd\"}" > /tmp/data.json
curl --silent \
-H "Content-Type: application/json" \
-d "@/tmp/data.json" \
-X POST $piston_api_url | jq -r '.output'
done
}
[[ $1 == "main" ]] && main
# Run it through rlwrap for gnu readline support.
rlwrap ./$0 main