Use AI To Create Bash Scripts Using Fig

If you’ve ever written a bash script, you’ll know exactly how hard it can be to do well. In this blog post, I’m going to show you how you can skip all of that and use AI to do it all for you!

We’ll be talking about one of my very favorite tools as a developer: Fig. Fig gives your terminal superpowers and provides intellisense for CLI tools, packages that you want to install from NPM, project scripts, and much more.

Fig Script Editor

Before we dive into using AI to create scripts, let’s take a quick look at the Fig Script Editor. With Fig, you can create a new script and give it a name, description, and even add user inputs. You can write your scripts in bash, JavaScript, or TypeScript.

Create a hello world script with Fig.ioLet’s say we have a simple script that echoes “Hello World.” We can add this script to Fig and run it by typing: fig run hello-world. Fig will then execute the script and output “Hello World.”

Combining Fig and AI to Generate Scripts

Now let’s create a script with AI using Fig’s integration with OpenAI’s Chatbot GPT. In this example, we will generate a bash script that kills a process running on a given port. The port number should be provided by the user as input. We can click the “AI Generate” button in Fig to use GPT for our script generation.

Generate a snippet using AI and Fig.ioAfter we provide GPT with our requirements, GPT comes back with the generated code snippet, title, and description of our script. The generated script is integrated into Fig, along with any user inputs. We can now run this script like any other script in Fig.

Run a fig script in the terminalFig provides us with a UI for the script, allowing us to input the port number we wish to kill the process at. After providing the input, the script runs, and if a process is running on the given port, it kills that process.

Additional Use Cases

There are countless use cases for generating scripts with AI and Fig. Here are few additional ideas I had:

  • Converting and resizing images
  • Automatically organizing files or folders
  • Generating default configuration files for new projects code


Fig is an amazing tool that can not only help you be more efficient when working with the terminal, but also opens up the possibility of using AI to generate scripts for various tasks you might encounter as a developer. If you haven’t already, make sure to check out Fig and give it a try.

My Weekly Newsletter

A weekly newsletter filled with personal updates, recent content, and general Web Development announcements to inspire you to Learn, Build, and Teach.