scrolex
It's like a ⌚ Rolex, except it has nothing to do with Rolexes and executes commands instead.
Scrolex executes commands, captures & scrolls back the output, optionally prefixing and overwriting each last line with the next. Here, a demo works better:
Demo
Install
yarn add scrolex || npm install scrolex --save
Use
First, require scrolex:
const scrolex =
Execute a shell command:
scrolex
Execute without a shell:
scrolex
Do not copy the command's output to the terminal:
scrolex
Overrule environment
scrolex
Announce the command you are executing:
scrolex // Announce also leaves a sticky line: `Successfully executed: ls -al` or `Failed to execute: ls -al`
Prefix output with ✔ myapp ❯ prepare ❯
:
scrolex
Add some ephemeral output, respecting the currently set prefix:
scrolex
Add some sticky output, respecting the currently set prefix:
scrolex
Use async/await
for shell-scripting super-powers ⚡
const serialExecution = async { try const cores = await scrolex if cores > 10 await scrolex const processTree = await scrolex catch err throw err }
Use Promises
for ... yeah why would you. But the important thing is you can!:
scrolex
Options
fatal
If set to true
, whenever exe
yields a non-zero exit code, the whole process stops with a dump of the combined
stderr & stdout on-screen. Useful for shell-scripting tasks. Default: false
.
env
Allows to specify the executed program's environment. If you want to add environment on top of the current environment use something like:
env: Object
Default: process.env
.
Global State (?!?!!!?‼️❓)
Yes, by default Scrolex uses global state (global.scrolex
) within a Node process to keep track of output
and so that options can be re-used across instances if you set them with persistOpts
. This makes it so
that consequent calls can be lightweight, as well as the output consistent looking.
If you'd rather ditch convenience in favor of strictness, or this causes a hard time testing, you are welcome to pass in your own state object, and Scrolex will happily use that instead:
const myLocalStateObject = {}scrolex
You can even pass a new state object each time to avoid any kind of magic inheritance:
scrolex
Here's how to make all subsequent scrolex.exe()
calls add their currently executing command
to the prefix:
scrolex
You can also persist upon requiring:
const scrolex = scrolex
Todo
See CHANGELOG.md
Changelog
See CHANGELOG.md
Authors
Related Projects
- listr: Nicer I'd say, but it does impose its structure on your code
License
Copyright (c) 2017 Kevin van Zonneveld. Licenses under MIT.