Watch-Go is a simple Golang script that behaves similarly to the Linux native command watch
.
Why?
I wanted to learn Golang and I really got tired of not having the watch
command from Linux on Windows devices.
What is it?
A simple tool that loops commands. I plan to build a lot more functionality into it over time but for now it primarily runs a given command on a given interval and reports some metrics if desired.
I thought this would be a fun challenge to start learning some basics of Golang and to gather an understanding of building a CLI. There will be flags and arguments built into as time goes on in order to more closely parallel the watch
command.
The project is setup to build via GitLab pipelines and can publish both a Windows and Linux executable from the one pipeline job. This is a powerful thing that I have never had access to before. I have experience in Java, JavaScript, and Python. All of these have some level of portability between Operating Systems (OS), however they lack a simplicity in their portability.
For example, I have not tried building native executables in Java but you have to deal with the JVM which can be clunky and memory hungry. I have built projects using Quarkus in the past and that is fast and lightweight, but still not really for native executables on your desktop.
NodeJS recently brought Single-Executable-Applications (SEA) into a stable state. This capacity allows pulling all of the necessary dependencies, along with the Node executable itself into a single runnable file. I have not tried compiling across OSes but that would be a limiting factor here for me.
Python has a few tools, notably PyInstaller and Nuitka, for compiling the source code into runnable files. Once again, cross OS compilation is not built into these tools and so if you want to build for Windows, you need to be running on Windows or trying to do some shenanigans with Wine. I have this working in some projects, but honestly it’s not great, especially when you want to build often in the GitLab pipeline space, aka inside of a container environment.
With all of that, I landed on Golang for my simple CLI tools. I hope this to be the start of many small, perhaps some larger CLIs. And all of those natively executable on multiple OSes so that I can switch between my Windows workstation, Linux laptop and servers, and who knows maybe one day a Mac.
Sources
- Watch-Go - GitLab
- Go - go.dev
- Quarkus - quarkus.io
- Node.js SEA - nodejs.org
- PyInstaller - pyinstaller.org
- Nuitka - nuitka.net