Write better shell scripts using NodeJS
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
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"
`
})
})()
Set custom configuration with setConfig
setConfig({
loggerLevel: 'verbose',
})
;(async () => {
await $`echo "Hello"`
})()
TBD
TBD
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.