Bonnie is a command aliasing tool. If you have a super-long command that you have to run all the time, Bonnie is for you! Just define the command in
bonnie.toml at the root of your project, and you're good to go!
[scripts] short = "really long command..."
For example, if you're running
docker-compose a lot, and you have a custom environment variables file, it's annoying to type out
docker-compose --env-file .my.env ... every time you want to do something! Bonnie can shorten this easily!
[scripts] dc = "docker-compose --env-file .my.env %%"
The double percent sign (
%%) at the end tells Bonnie to append any arguments you provide to the end of the command.
You can even insert custom arguments into custom places in a custom order!
[scripts] greet.cmd = "echo \"Greetings %lastname. I see your…
So, I decided to try out Elm, a functional programming language with no runtime errors (yes, only compile-time errors). It's fantastic! However, Elm is not designed for the backend, so I decided to finally learn Rust, something I've been meaning to do for about a year now.
Having adopted these two new languages, I found myself wanting a good system to shorten commands for me - like NPM or Yarn scripts. Make was the most obvious option, but it feels somewhat overkill for essentially an aliasing system. Makefiles also have their own syntax, which, although miniscule, was not something I had any desire to delve into. Instead, I decided my first Rust project would be a replacement for NPM and Yarn scripts - Bonnie!
Bonnie is a super-fast command aliasing tool designed to replace NPM or Yarn scripts entirely. You can define simple commands like so:
[scripts] greet = "echo Hello World"
And then run them like this:
You can mimic the default behavior of NPM and Yarn scripts, to append any given arguments to the end of the command, by adding the double percent sign (
%%) to the end of the command:
[scripts] greet = "echo Hello %%"
And you can add arguments to the end easily when you run it:
bonnie greet Donald Knuth in math-land
You can even add specific arguments for aliases to take:
[scripts] greet.cmd = "echo Hello %firstname %lastname" greet.args = [ "firstname", "lastname" ]
And those can be run like so:
bonnie greet Donald Knuth
Bonnie will gracefully tell you when you've done something wrong, like provided too few arguments, or used invalid syntax in your config file. By default, that config is stored at
bonnie.toml, but you can specify an alternative path by setting the
BONNIE_CONF environment variable.
This is my first ever CLI, and it's also the first time I've used GitHub Actions to automate building my code on different OSes! Bonnie has binaries available for Linux, MacOS, and Windows on the releases page.
I think Bonnie has been a great opportunity for me to dive into a complex language like Rust head-first, because no matter how long you spend poring over the Rust Book (about 7 hours in my case), you can never learn programming without actually building something. In the particular case of Rust, you can never get your head around lifetimes without actually building something!
I'm using Bonnie daily now, and so far it's working really well! I'm not aware of any alternatives to NPM and Yarn scripts that are as simple as Bonnie, and I hope this will help some people!