unshell
v0.10.3
Published
Set your shell free
Downloads
6
Readme
shell
Set your shell free !
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
npm install -g unshell
Embedded script inside apps
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
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
unshell run pause.js
Embedded script inside apps
Given the precedent script pause.js
Run it with zeit/micro
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
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.