I like JavaScript and I don't like bash! And today I'd like to share with you a tool that allows me to do less of the latter: zx.
There are several ways to install it, with Deno you could do it like so:
deno install --global -A npm:zx
Create a script, e.g. list.ts
:
#!/usr/bin/env zx
import { $ } from 'npm:zx'
const list = await $`ls`
console.log(list)
Allow execution as a script:
chmod +x list.ts
And, finally, run it:
./list.ts
Isn't it awesome?! You can use any command available on your machine, check this example out:
#!/usr/bin/env zx
await $`cat package.json | grep name`
const branch = await $`git branch --show-current`
await $`dep deploy --branch=${branch}`
await Promise.all([
$`sleep 1; echo 1`,
$`sleep 2; echo 2`,
$`sleep 3; echo 3`,
])
const name = 'foo bar'
await $`mkdir /tmp/${name}`
And, as any other package, you could use zx
as a library. Imagine all the cool things you could build!
Liked the content and would love to have more of it all year long?
Top comments (0)