Make cli commands yoinkable into cosmo shell

This lets our system() and popen() commands function sort of like
BusyBox and ToyBox. By default the Cosmopolitan Shell is lightweight.
But if you use STATIC_YOINK then you can pull the individual commands
you want into the linkage, and they'll be included in a single binary.
For example the demo binary embeds `tr` and `sed` and ends up ~140kb.
This commit is contained in:
Justine Tunney 2022-10-14 16:37:29 -07:00
parent 5af19b7eed
commit 3d2d04b25e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
32 changed files with 897 additions and 276 deletions

View file

@ -7,13 +7,20 @@
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/dce.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
/**
* @fileoverview Cosmopolitan Command Interpreter Demo
* Yes this works on Windows.
*/
STATIC_YOINK("_tr");
STATIC_YOINK("_sed");
int main(int argc, char *argv[]) {
if (IsWindows()) {
system("notepad");
} else {
system("ls | tr a-z A-Z");
}
system("x=world\n"
"echo hello $x |\n"
" tr a-z A-Z |\n"
" sed 's/\\(.\\)/\\1 /g'");
}