Skip to content

Commit

Permalink
#649 - syntax for calling external programs without capturing the output
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyash-b committed Jul 10, 2024
1 parent 912737d commit 448a5d2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Add `Transformed` pattern
* Add experimental `Capture` pattern for capturing values
* Add experimental `Branch` pattern for multiple matches
* Add `$[...]` syntax for running external programs without capturing output

### Fixes and improvements
* Fix `AtPath` for non-eachables
Expand Down
8 changes: 8 additions & 0 deletions lib/stdlib.ngs
Original file line number Diff line number Diff line change
Expand Up @@ -6806,6 +6806,14 @@ TEST "$(/bin/echo -n abc)" == 'abc'
TEST $(cd:"/" pwd).lines()[0] == '/'
TEST t=TmpFile(); $(echo -n abc >$t); t.read() == "abc"

doc Same as $(top_level:: ...) - run the commands without capturing the stdout/stderr.
doc Use the same stdout/stderr as the parent process (your script).
F '$[]'(cp:CommandsPipeline) {
debug("process2", { "Using \$[] to set top_level:: for ${cp}" })
cp.options.top_level = true
$($cp)
}

doc Write to first process of ProcessesPipeline
doc %EX - p = (|cat -n | tac >/tmp/1)
doc %EX - p.write("one\n")
Expand Down
3 changes: 2 additions & 1 deletion syntax.leg
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ identifier =
ret->name = ngs_strdup(yytext);
$$ = ret;
}
| "(" <("$()" | [-|=!@?~+*/%$<>.\[\]:]+ | "is not" | "not in")> ")" {
| "(" <("$()" | "$[]" | [-|=!@?~+*/%$<>.\[\]:]+ | "is not" | "not in")> ")" {
MAKE_NODE(ret, IDENTIFIER_NODE);
ret->name = ngs_strdup(yytext);
$$ = ret;
Expand Down Expand Up @@ -1721,6 +1721,7 @@ optional-function-call-arguments =

subshell =
"$(" cmd:commands-pipeline ")" { $$ = cmd; }
| "$[" cmd:commands-pipeline "]" { $$ = cmd; cmd->first_child->name = ngs_strdup("$[]"); $$ = cmd; }
| "%(" cmd:commands-pipeline ")" { cmd->first_child->name = ngs_strdup("%()"); $$ = cmd; }
| "``" cmd:commands-pipeline "``" { cmd->first_child->name = ngs_strdup("````"); $$ = cmd; }
| "`" cmd:commands-pipeline "`" { cmd->first_child->name = ngs_strdup("``"); $$ = cmd; }
Expand Down

0 comments on commit 448a5d2

Please sign in to comment.