Nutshell
Write better shell scripts using NodeJS
Nutshell
Node Useful Tool for Shell
Create a example.js
#!/usr/bin/env nutshell
;(async () => {
await $`echo "Hello"`
await $`
echo "Multiline commands"
echo "using template literals"
`
await withContext(async () => {
await $`
echo "I am running"
echo "in a separated process"
`
})
})()
Run with:
./example.js
Using Typescript
For usage with Typescript, change intepreter to ts-node
.
You should have ts-node
installed.
#!/usr/bin/env ts-node
// import to enable type checking
import '@rondymesquita/nutshell'
;(async () => {
await $`echo "Hello"`
await $`
echo "Multiline commands"
echo "using template literals"
`
await withContext(async () => {
await $`
echo "I am running"
echo "in a separated process"
`
})
})()
Configuration
Set custom configuration with setConfig
setConfig({
loggerLevel: 'verbose',
})
;(async () => {
await $`echo "Hello"`
})()
Configuration options
TBD
API
TBD
Motivation
Sometimes, writing shell scripts can be challenging, specially when we need to do conditionals, loops, reading files like JSON or YAML. Nutshell helps in these cases leveraging the knowledge in Javascript without being too far of Shell Scripts.
Logo By icons8
Inspired by Google zx, but using libraries I personaly prefer.