diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-06-15 16:21:50 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-06-15 16:21:50 -0700 |
| commit | ff800b2377883f9df5b73cd5a4bb9e98141d835e (patch) | |
| tree | dfe3a17c14ee6c96ab096bfb9acf7607b901c346 /bb.c | |
| parent | f372995750c21984d12076b98e14e10f38d63ca6 (diff) | |
Allow piping in commands when launching bb (e.g. `printf '+sel:%s\0' * |
bb`)
Diffstat (limited to 'bb.c')
| -rw-r--r-- | bb.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -1430,7 +1430,7 @@ int main(int argc, char *argv[]) sprintf(depthstr, "%d", depth + 1); setenv("BB_DEPTH", depthstr, 1); setenv("BBCMD", cmdfilename, 1); - } else if (cmd_args > 0) { + } else { char *parent_bbcmd = getenv("BBCMD"); if (!parent_bbcmd || parent_bbcmd[0] == '\0') { initial_path = "."; @@ -1489,6 +1489,14 @@ int main(int argc, char *argv[]) } } + struct pollfd pfd = {STDIN_FILENO, POLLIN, 0}; + if (poll(&pfd, 1, 0) == 1 && pfd.revents & POLLIN) { + ssize_t len; + char buf[1024]; + while ((len = read(STDIN_FILENO, buf, sizeof(buf))) > 0) + write(cmdfd, buf, (size_t)len); + } + if (cmdfd != -1) { close(cmdfd); cmdfd = -1; |
