Tôi là Duyệt

zx

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

zx