Reorder sections in `docs/scripts.md` (#876)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 7b044bb · Browse files · 1 file·+168 added−168 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+168 added−168 removed
- other:+168 added−168 removed
Provenance
- Commit
2cd41ef- Tree
632697a- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
7b044bb
1 file changed+168 added−168 removed
modified:docs/scripts.md+168 added-168 removed
143 unmodified lines144 --example-flag-one145 --example-flag-two`146 ```147 148-### Subcommands148+### Concatenation149 150 ```sh151 # Bash152-echo "$(echo example)"152+tmpDir="/tmp"153+mkdir "$tmpDir/filename"154 ```155 156 ```js157 // zx157-const example = await $`echo example`;158-await $`echo ${example}`;158+const tmpDir = '/tmp'159+await $`mkdir ${tmpDir}/filename`;160 ```161 162 ```js163 // Execa163-const example = await $`echo example`;164-await $`echo ${example}`;164+const tmpDir = '/tmp'165+await $`mkdir ${tmpDir}/filename`;166 ```167 167-### Concatenation168+### Variable substitution169 170 ```sh171 # Bash171-tmpDir="/tmp"172-mkdir "$tmpDir/filename"172+echo $LANG173 ```174 175 ```js176 // zx177-const tmpDir = '/tmp'178-await $`mkdir ${tmpDir}/filename`;177+await $`echo $LANG`;178 ```179 180 ```js181 // Execa183-const tmpDir = '/tmp'184-await $`mkdir ${tmpDir}/filename`;182+await $`echo ${process.env.LANG}`;183 ```184 187-### Parallel commands185+### Escaping186 187 ```sh188 # Bash191-echo one &192-echo two &189+echo 'one two'190 ```191 192 ```js193 // zx197-await Promise.all([$`echo one`, $`echo two`]);194+await $`echo ${'one two'}`;195 ```196 197 ```js198 // Execa202-await Promise.all([$`echo one`, $`echo two`]);199+await $`echo ${'one two'}`;200 ```201 205-### Serial commands202+### Escaping multiple arguments203 204 ```sh205 # Bash209-echo one && echo two206+echo 'one two' '$'207 ```208 209 ```js210 // zx214-await $`echo one && echo two`;211+await $`echo ${['one two', '$']}`;212 ```213 214 ```js215 // Execa219-await $`echo one`;220-await $`echo two`;216+await $`echo ${['one two', '$']}`;217 ```218 223-### Local binaries219+### Subcommands220 221 ```sh222 # Bash227-npx tsc --version223+echo "$(echo example)"224 ```225 226 ```js227 // zx232-await $`npx tsc --version`;228+const example = await $`echo example`;229+await $`echo ${example}`;230 ```231 232 ```js233 // Execa237-await $`tsc --version`;234+const example = await $`echo example`;235+await $`echo ${example}`;236 ```237 240-### Builtin utilities238+### Serial commands239 240+```sh241+# Bash242+echo one && echo two243+```244+245 ```js246 // zx244-const content = await stdin();247+await $`echo one && echo two`;248 ```249 250 ```js251 // Execa249-import getStdin from 'get-stdin';252+await $`echo one`;253+await $`echo two`;254+```255 251-const content = await getStdin();256+### Parallel commands257+258+```sh259+# Bash260+echo one &261+echo two &262 ```263 254-### Variable substitution264+```js265+// zx266+await Promise.all([$`echo one`, $`echo two`]);267+```268 269+```js270+// Execa271+await Promise.all([$`echo one`, $`echo two`]);272+```273+274+### Global/shared options275+276 ```sh277 # Bash258-echo $LANG278+options="timeout 5"279+$options echo one280+$options echo two281+$options echo three282 ```283 284 ```js285 // zx263-await $`echo $LANG`;286+const timeout = '5s';287+await $`echo one`.timeout(timeout);288+await $`echo two`.timeout(timeout);289+await $`echo three`.timeout(timeout);290 ```291 292 ```js293 // Execa268-await $`echo ${process.env.LANG}`;294+import {$ as $_} from 'execa';295+296+const $ = $_({timeout: 5000});297+298+await $`echo one`;299+await $`echo two`;300+await $`echo three`;301 ```302 303 ### Environment variables304 13 unmodified lines318 // Execa319 await $({env: {EXAMPLE: '1'}})`example_command`;320 ```321 290-### Escaping322+### Local binaries323 324 ```sh325 # Bash294-echo 'one two'326+npx tsc --version327 ```328 329 ```js330 // zx299-await $`echo ${'one two'}`;331+await $`npx tsc --version`;332 ```333 334 ```js335 // Execa304-await $`echo ${'one two'}`;336+await $`tsc --version`;337 ```338 307-### Escaping multiple arguments339+### Builtin utilities340 341+```js342+// zx343+const content = await stdin();344+```345+346+```js347+// Execa348+import getStdin from 'get-stdin';349+350+const content = await getStdin();351+```352+353+### Printing to stdout354+355 ```sh356 # Bash311-echo 'one two' '$'357+echo example358 ```359 360 ```js361 // zx316-await $`echo ${['one two', '$']}`;362+echo`example`;363 ```364 365 ```js366 // Execa321-await $`echo ${['one two', '$']}`;367+console.log('example');368 ```369 324-### Current filename370+### Silent stderr371 372 ```sh373 # Bash328-echo "$(basename "$0")"374+echo example 2> /dev/null375 ```376 377 ```js378 // zx333-await $`echo ${__filename}`;379+await $`echo example`.stdio('inherit', 'pipe', 'ignore');380 ```381 382 ```js337-// Execa338-import {fileURLToPath} from 'node:url';339-import path from 'node:path';340-341-const __filename = path.basename(fileURLToPath(import.meta.url));342-343-await $`echo ${__filename}`;383+// Execa does not print stdout/stderr by default384+await $`echo example`;385 ```386 387 ### Verbose mode388 25 unmodified lines414 ```415 NODE_DEBUG=execa node file.js416 ```417 377-### Current directory418+### Piping stdout to another command419 420 ```sh421 # Bash381-cd project422+echo npm run build | sort | head -n2423 ```424 425 ```js426 // zx386-cd('project');387-388-// or:389-$.cwd = 'project';427+await $`npm run build | sort | head -n2`;428 ```429 430 ```js431 // Execa394-const $$ = $({cwd: 'project'});432+await $`npm run build`433+ .pipe`sort`434+ .pipe`head -n2`;435 ```436 397-### Multiple current directories437+### Piping stdout and stderr to another command438 439 ```sh440 # Bash401-pushd project402-pwd403-popd404-pwd441+echo example |& cat442 ```443 444 ```js445 // zx409-within(async () => {410- cd('project');411- await $`pwd`;412-});413-414-await $`pwd`;446+const echo = $`echo example`;447+const cat = $`cat`;448+echo.pipe(cat)449+echo.stderr.pipe(cat.stdin);450+await Promise.all([echo, cat]);451 ```452 453 ```js454 // Execa419-await $({cwd: 'project'})`pwd`;420-await $`pwd`;455+await $({all: true})`echo example`456+ .pipe({from: 'all'})`cat`;457 ```458 423-### Exit codes459+### Piping stdout to a file460 461 ```sh462 # Bash427-false428-echo $?463+echo example > file.txt464 ```465 466 ```js467 // zx433-const {exitCode} = await $`false`.nothrow();434-echo`${exitCode}`;468+await $`echo example`.pipe(fs.createWriteStream('file.txt'));469 ```470 471 ```js472 // Execa439-const {exitCode} = await $({reject: false})`false`;440-console.log(exitCode);473+await $({stdout: {file: 'file.txt'}})`echo example`;474 ```475 443-### Timeouts476+### Piping stdin from a file477 478 ```sh479 # Bash447-timeout 5 echo example480+echo example < file.txt481 ```482 483 ```js484 // zx452-await $`echo example`.timeout('5s');485+const cat = $`cat`486+fs.createReadStream('file.txt').pipe(cat.stdin)487+await cat488 ```489 490 ```js491 // Execa457-await $({timeout: 5000})`echo example`;492+await $({inputFile: 'file.txt'})`cat`493 ```494 460-### PID461-462-```sh463-# Bash464-echo example &465-echo $!466-```467-468-```js469-// zx does not return `childProcess.pid`470-```471-472-```js473-// Execa474-const {pid} = $`echo example`;475-```476-495 ### Errors496 497 ```sh498 # Bash communicates errors only through the exit code and stderr70 unmodified lines569 // isTerminated: false570 // }571 ```572 555-### Global/shared options573+### Exit codes574 575 ```sh576 # Bash559-options="timeout 5"560-$options echo one561-$options echo two562-$options echo three577+false578+echo $?579 ```580 581 ```js582 // zx567-const timeout = '5s';568-await $`echo one`.timeout(timeout);569-await $`echo two`.timeout(timeout);570-await $`echo three`.timeout(timeout);583+const {exitCode} = await $`false`.nothrow();584+echo`${exitCode}`;585 ```586 587 ```js588 // Execa575-import {$ as $_} from 'execa';576-577-const $ = $_({timeout: 5000});578-579-await $`echo one`;580-await $`echo two`;581-await $`echo three`;589+const {exitCode} = await $({reject: false})`false`;590+console.log(exitCode);591 ```592 584-### Background processes593+### Timeouts594 595 ```sh596 # Bash588-echo one &597+timeout 5 echo example598 ```599 600 ```js592-// zx does not allow setting the `detached` option601+// zx602+await $`echo example`.timeout('5s');603 ```604 605 ```js606 // Execa597-await $({detached: true})`echo one`;607+await $({timeout: 5000})`echo example`;608 ```609 600-### Printing to stdout610+### Current filename611 612 ```sh613 # Bash604-echo example614+echo "$(basename "$0")"615 ```616 617 ```js618 // zx609-echo`example`;619+await $`echo ${__filename}`;620 ```621 622 ```js623 // Execa614-console.log('example');615-```624+import {fileURLToPath} from 'node:url';625+import path from 'node:path';626 617-### Piping stdout to another command627+const __filename = path.basename(fileURLToPath(import.meta.url));628 619-```sh620-# Bash621-echo npm run build | sort | head -n2629+await $`echo ${__filename}`;630 ```631 624-```js625-// zx626-await $`npm run build | sort | head -n2`;627-```632+### Current directory633 629-```js630-// Execa631-await $`npm run build`632- .pipe`sort`633- .pipe`head -n2`;634-```635-636-### Piping stdout and stderr to another command637-634 ```sh635 # Bash640-echo example |& cat636+cd project637 ```638 639 ```js640 // zx645-const echo = $`echo example`;646-const cat = $`cat`;647-echo.pipe(cat)648-echo.stderr.pipe(cat.stdin);649-await Promise.all([echo, cat]);641+cd('project');642+643+// or:644+$.cwd = 'project';645 ```646 647 ```js648 // Execa654-await $({all: true})`echo example`655- .pipe({from: 'all'})`cat`;649+const $$ = $({cwd: 'project'});650 ```651 658-### Piping stdout to a file652+### Multiple current directories653 654 ```sh655 # Bash662-echo example > file.txt656+pushd project657+pwd658+popd659+pwd660 ```661 662 ```js663 // zx667-await $`echo example`.pipe(fs.createWriteStream('file.txt'));664+within(async () => {665+ cd('project');666+ await $`pwd`;667+});668+669+await $`pwd`;670 ```671 672 ```js673 // Execa672-await $({stdout: {file: 'file.txt'}})`echo example`;674+await $({cwd: 'project'})`pwd`;675+await $`pwd`;676 ```677 675-### Piping stdin from a file678+### Background processes679 680 ```sh681 # Bash679-echo example < file.txt682+echo one &683 ```684 685 ```js683-// zx684-const cat = $`cat`685-fs.createReadStream('file.txt').pipe(cat.stdin)686-await cat686+// zx does not allow setting the `detached` option687 ```688 689 ```js690 // Execa691-await $({inputFile: 'file.txt'})`cat`691+await $({detached: true})`echo one`;692 ```693 694-### Silent stderr694+### PID695 696 ```sh697 # Bash698-echo example 2> /dev/null698+echo example &699+echo $!700 ```701 702 ```js702-// zx703-await $`echo example`.stdio('inherit', 'pipe', 'ignore');703+// zx does not return `childProcess.pid`704 ```705 706 ```js707-// Execa does not forward stdout/stderr by default708-await $`echo example`;707+// Execa708+const {pid} = $`echo example`;709 ```