An open API service indexing awesome lists of open source software.

https://github.com/romainprignon/unshell

Set your shell free !
https://github.com/romainprignon/unshell

exec scripting shell

Last synced: about 1 year ago
JSON representation

Set your shell free !

Awesome Lists containing this project

README

          

# ![un](./unshell.png) shell

> Set your shell free !

![](https://github.com/romainprignon/unshell/workflows/ci/badge.svg)

Combine the flexibility of a programming language with the knowledge of shell command.
As developer, sometimes, we need to run shell scripts. It will be cool to do so with the familiarity of a programming language.
An an ops, sometimes, we need to run complex shell scripts. It will be cool to do so with the power of a programming language.

## Features

* **Light**: There are no dependencies
* **Easy**: A small abstraction over `child_process`
* **Async**: Work with async/await command
* **Testable**: Unshell script are easily testable because they yield execution control

## Setup

Execute script through Shell
```sh
npm install -g unshell
```

Embedded script inside apps
```sh
npm install unshell
```

## Usage

### Execute script through Shell
```
Execute script through unshell runtime

Usage:
unshell COMMAND [SCRIPT_PATH] [ARGS...]

Commands:
help Print this help message
run run a script through unshell runtime
```

Given the script: `pause.js` to pause all docker containers
```js
module.exports = function * pause () {
const ids = yield * fetchContainerIds()

for(const id of ids) {
yield `docker pause ${id}`
}
}

function * fetchContainerIds () {
const ids = yield `docker ps -q --no-trunc`

return ids.split('\n').filter(Boolean)
}
```

Run it through unshell
```sh
unshell run pause.js
```

### Embedded script inside apps
Given the precedent script `pause.js`
Run it with `zeit/micro`
```js
module.exports = (req, res) => {
const {resolve} = require('path')
const {unshell} = require('unshell')

try {
const script = require(resolve('./scripts/pause.js'))
unshell({env: process.env})(script)

res.end('OK')
} catch (err) {
res.end('NOK')
}
}
```

## Examples
Here is some examples of what you can do with unshell
- [Pause containers](examples/pause-resume-container)

## Contribute
Please check out the issues labeled `help wanted` or `good-first-issue`. Try npx good-first-issue unshell

## License

The code is available under the [MIT license](LICENSE).