Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/linkdd/tshellout
Typescript Shell Out library, to simplify writing and composing shell commands for NodeJS
https://github.com/linkdd/tshellout
nodejs shell typescript
Last synced: 2 months ago
JSON representation
Typescript Shell Out library, to simplify writing and composing shell commands for NodeJS
- Host: GitHub
- URL: https://github.com/linkdd/tshellout
- Owner: linkdd
- License: mit
- Created: 2023-07-19T18:30:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-18T16:45:03.000Z (over 1 year ago)
- Last Synced: 2024-10-29T05:45:40.500Z (2 months ago)
- Topics: nodejs, shell, typescript
- Language: TypeScript
- Homepage:
- Size: 67.4 KB
- Stars: 24
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# TShellOut
Typescript Shell Out library, to simplify writing and composing shell commands
for NodeJS.## :sparkles: Features
- No dependencies
- Composing commands with pipes (`|`), and sequential operators (`&&`, `||`)
- Redirecting stdin, stdout and stderr
- Writing Typescript strings to stdin## :memo: Usage
Install the package:
```
$ npm i tshellout
```Then in a script:
```typescript
import { command, script } from 'tshellout'const cmd = command('echo', 'hello world')
const res = await cmd.run()console.log(res.exitCode)
console.log(res.stdout.toString())
console.log(res.stderr.toString())
```More examples:
```typescript
// echo "hello world" | tr -d "\r" | tr -d "\n" | wc -c
const cmd = command('echo', 'hello world')
.pipe(command('tr', '-d', '"\\r"'))
.pipe(command('tr', '-d', '"\\n"'))
.pipe(command('wc', '-c'))
const res = await cmd.run()
``````typescript
// myscript.sh || exit 1
const cmd = command('myscript.sh')
.or(command('exit', '1'))
const res = await cmd.run()
``````typescript
// script-1.sh && script-2.sh
const cmd = command('script-1.sh')
.and(command('script-2.sh'))
const res = await cmd.run()
``````typescript
// (script-1.sh || script-2.sh) && script-3.sh
const cmd = command('script-1.sh')
.or(command('script-2.sh'))
.and(command('script-3.sh'))
const res = await cmd.run()
``````typescript
// echo "hello world" > greet.txt
const cmd = command('echo', 'hello world')
.redirectStdout('greet.txt')
const res = await cmd.run()
``````typescript
// cat << data.txt
const cmd = command('cat')
.redirectStdin('data.txt')
const res = await cmd.run()
``````typescript
// cat <