I fixed Google’s scripting tool

Tushar Sadhwani
2 min readMay 8, 2021

So someone at Google released a tool called zx a couple days ago, and…

Well, take a look at it for yourself:

I can’t be the only one who hates:

  1. The idea of having to install nodejs and npm on my servers just to run a shell script.
  2. The await $`...` syntax used for every. single. command.

And I thought I could do better, so I tried. And this is what I came up with:

Introducing zxpy

#! /usr/bin/env zxpy
~'echo Hello world!'
file_count = ~'ls -1 | wc -l'
print("file count is:", file_count)

It fixes the two problems I had in the following ways:

  • It uses Python instead. Not only is Python a much more popular choice for scripting on desktop, it is also pre-installed on a lot more systems. Most linux and MacOS desktops, and arch/ubuntu based linux servers ship with it installed (probably many others do as well!)
  • It uses a simple ~'shell command' syntax. It's synchronous by default, but in my experience, most shell scripts are as well. It is possible to add async support, and if needed I'll add it in the future, but synchronous as default seems a lot more sane to me. :)
More extensive examples available on GitHub!

So, why not give it a try?

It’s available on pip, and the source code, along with a few examples, is available on GitHub.

--

--