Brev.dev, inc of San Francisco, California, USA has been acquired by NVIDIA Corporation of Santa Clara, California, USA on July 2024

BlogPricing

Dev Challenges

Using ChatGPT to make Bash palatable

Nader Khalil

December 21, 20226 min read

AI as a great framework for bash

As a founder, I find myself context-switching a lot-- jumping between sales, marketing, and development tasks constantly. What I want to be able to do is easily jump between contexts in my browser: when I type “marketing” in my terminal, my browser should close all current tabs and then reopen only my “marketing” tabs. Same for “sales,” “dev,” and so on.

My initial idea was to hack this together with a CLI framework like Cobra in Golang which is well documented and affords maintainable projects, until a coworker mentioned I should just do this in bash. I thought this was an awful suggestion.

It was only when ChatGPT came along that I realised using bash for this project might actually be worth a shot. Bash is a powerful and versatile language. It’s ubiquitous, being available on any Unix shell— no frameworks, environment issue, installations, etc. But it fucking sucks. Like, it’s truly awful to write, but ChatGPT is incredible when it comes to writing code with evasive syntax.

First, I asked ChatGPT to “Make a bash script that opens google chrome to https://twitter.com and https://mixpanel.com".

img

And it fails: zsh: command not found: google-chrome

Hmm, I wonder if that’s just for Linux. I just fed the errors back to ChatGPT. “Make it work for mac"

img

Great!! It works and opens the tabs. When I use git branch to move between states of the code base, it removes any code from the previous branch. I need this to exit the current browser window before opening the tabs. Hey ChatGPT, “make sure to close the existing window first.”

img

Excellent! Now I have to think about the branch names. For starters, what if it was just a simple text file to track the branch state? So dev.txt would have my dev tabs, and marketing.txt would have my marketing tabs.

img

Now I need to feed the script a branch name, so ./script marketing to open my marketing tabs. I need this script to accept an argument.

img

Hahaha! It works!

img

Rather than building complicated software using complicated frameworks aimed at making the life of a developer easier, I used basic bash scripts to finish my project in ~15 lines of code, which you can checkout here. And using Bash for a project isn’t a death sentence when equipped with AI to provide the ergonomics, rather than the complex frameworks.

AI works best at enabling professionals, not replacing them

The motion of coding with ChatGPT is the same as coding without it.

You generate some code, wrestle it to pass the compiler or fit some use case, and repeat. I was still programming and hacking away even if I didn’t spending time coding. I got the same frustrations when things didn’t work and the same joy when it finally did.

AI is not here to replace us. Not that it can’t, it just works much better enabling professionals to be directors of their work.

AI needs to be funny when wrong and scary when right. Without a professional at the helm, the lack of understanding of what was generated makes AI extremely limiting. But with a professional leveraging it, generative AI being wrong is no different than a self-induced compiler error— it’s an invitation to debug.

Leveraging AI for the more pedantic parts of the job seems to be the killer use case, and leaning on it for developer ergonomics seems to take away a bunch of unnecessary complexity.

Previous
How to create and manage remote dev environments with IaaC