zx
Note: This post is over 5 years old. The information may be outdated.
A tool for writing better scripts by Google - zx.
I usually choose to write a Python or Deno script instead of a shell script for more convenience.
I found this tool is so great, helping to write the script quickly.
It would help if you tried it too.
Refer to the Git repo here for the detailed document: https://github.com/google/zx
Some examples
backup-github.mjs
#!/usr/bin/env zx
let username = await question('What is your GitHub username? ')
let token = await question('Do you have GitHub token in env? ', {
choices: Object.keys(process.env),
})
let headers = {}
if (process.env[token]) {
headers = {
Authorization: `token ${process.env[token]}`,
}
}
let res = await fetch(`https://api.github.com/users/${username}/repos`, {
headers,
})
let data = await res.json()
let urls = data.map((x) => x.git_url)
await $`mkdir -p backups`
cd('./backups')
await Promise.all(urls.map((url) => $`git clone ${url}`))
zx ./backup-github.mjs
External files
zx https://gist.githubusercontent.com/duyet/04fe68cc1ce7c82360354a90824a5edd/raw/6e4dbcd74688fd492cbbb1f746e501f77c3f93d0/wttr.mjs
Related Posts
Uptime with GitHub Actions
Hey, I just found this tool, so incredibly clever that it uses Github Actions for uptime monitor and status page.
From Docker to Podman on MacOS
I'm looking for some of alternatives for Docker. Currently, there are a few of container technologies which are Docker’s most direct competitors, such as rkt, Podman, containerd, ...
Bitbucket Pipelines Notes
Bitbucket Pipelines document is fragmented everywhere. It always makes me search for a while every time I write a new one for CI/CD. So I'll make a few notes here.
My Neovim Setup in 2023
It's been years since I first started using neovim and I've been updating it regularly ever since.