code / nomsu

Lines6.6K Lua5.1K PEG1.3K make117
2 others 83
Markdown60 Bourne Again Shell23
(32 lines)
1 #!/usr/bin/env nomsu -V7.0.0
2 ###
3 This file defines some actions for running shell commands.
5 external:
6 (at $callsite =sh $cmd) means:
7 $f = ($io.popen $cmd)
8 $contents = ($f, read "*a")
9 [$ok, $return_type, $return] = ($f, close)
10 unless $ok:
11 if ($return_type == "exit"):
12 at $callsite fail
13 "Command failure: Command `\($cmd)` failed with exit code \$return"
14 ..else:
15 at $callsite fail
16 "Command failure: Command `\($cmd)` was terminated by signal \$return"
18 return $contents
20 (at $callsite sh> $cmd) means:
21 [$ok, $return_type, $return] = ($os.execute $cmd)
22 unless $ok:
23 if ($return_type == "exit"):
24 at $callsite fail
25 "Command failure: Command `\($cmd)` failed with exit code \$return"
26 ..else:
27 at $callsite fail
28 "Command failure: Command `\($cmd)` was terminated by signal \$return"
30 ### Attach callsite information for better error reporting
31 (=sh $cmd) compiles to \(at \("Text" tree with "\($cmd.source)") =sh \$cmd)
32 (sh> $cmd) compiles to \(at \("Text" tree with "\($cmd.source)") sh> \$cmd)