-
-
Notifications
You must be signed in to change notification settings - Fork 0
$sh
Eugene Lazutkin edited this page Sep 6, 2024
·
6 revisions
$sh is a set of helper functions to run shell-specific commands and/or use them in stream pipelines.
This function mirrors $ but runs the command with a shell.
import {$sh} from 'dollar-shell';The TypeScript declaration:
interface ShellImpl<R = string> extends Dollar<Promise<DollarResult>, ShellOptions> {
from: Dollar<ReadableStream<R>, ShellOptions>;
to: Dollar<WritableStream<R>, ShellOptions>;
through: Dollar<DuplexPair<R>, ShellOptions>;
io: Dollar<DuplexPair<R>, ShellOptions>;
}
declare const $sh: ShellImpl;The definition for ShellOptions can be found in shell(). The definition for Dollar
can be found in $$.
The rest is identical to $: $sh, $sh.from, $sh.to and $sh.io/$sh.through.
You can run $ examples with $sh. It'll be less efficient but it'll work. Generally, it should
be used for shell-specific tasks like running aliases or functions. Another possible use case is
to use shell pipes in the command.
This example runs bash function available only in the interactive mode:
import {$sh} from 'dollar-shell';
// custom alias that prints `stdout` and runs an interactive shell
const $p = $sh({shellArgs: ['-ic'], stdout: 'inherit'});
const result = await $p`nvm ls`;
// prints to the console the result of the command
await $p`ls -l . | grep LICENSE | wc`;
// prints to the console the result of the command