Convert Plain English To Commands Using GPT-3 Powered Shell Genie

Shell Genie OpenAI GPT-3 plain english to terminal commands

Shell Genie is a new command line tool that can be used to ask in plain English how to perform various tasks, and it gives you the shell command you need. To generate the commands, it uses OpenAI's GPT-3 or Free Genie, a free to use backend provided by the Shell Genie developer.

Once Shell Genie shows a command, it will ask if you want to run it. Make sure you understand the command before doing that! You could use something like Explain Shell to understand what the command does. Also, it's probably best you only use this for queries / commands that can't break things on your computer. Not all commands will work as expected, so use this at your own risk!

This is Shell Genie in action:

$ shell-genie ask "find all files that have been changed in the last 3 days from the current directory and subdirectories, with details"

Command: find . -mtime -3 -ls

$ shell-genie ask "use ffmpeg to extract audio from video without re-encoding it"

Command: ffmpeg -i <input_video_file> -vn -acodec copy <output_audio_file>

$ shell-genie ask "replace all instances of ^ with / in all .sh files in the current folder"

Command: sed -i 's/\^/\//g' *.sh

You can ask it to perform more complex commands as well, just make sure your query includes the correct keywords – your query is very important:

$ shell-genie ask "replace all instances of ^ with / in all .php files in the current folder that have been modified in the last 2 days"

Command: find . -name "*.php" -mtime -2 -exec sed -i 's/\^/\//g' {} \;

The tool can also explain the command, for example:

$ shell-genie ask "find all files that have been changed in the last 3 days from the current directory and subdirectories, with details" --explain

Command: find . -type f -mtime -3 -ls

Description: This command will search the current directory and all subdirectories for files that have been modified in the last 3 days. The -type f option specifies that only files should be searched, the -mtime -3 option specifies that only files modified in the last 3 days should be searched, and the -ls option provides detailed information about the files found.

This renders my article on how to find files modified in the last days or minutes (and others)… useless. Oh, well 😀️.

I've been using Shell Genie for a couple of days, and the displayed commands were spot on in most cases. When they weren't, it was usually due to user error – I didn't explain what I wanted to do well enough. Don't assume the tool understands what you want it to do, spell it! And remember, you're explaining what you want to do to a machine, and not a human. I should also mention that I've used Shell Genie with the OpenAI GPT-3 backend, and not the Free Genie backend.

If you choose to do run the command, and you're using the Free Genie backend, and not the OpenAI GPT-3 one, you can provide feedback to help improve the tool. Note that the Free Genie server stores the requested commands, OS, and shell version to improve the model. Also, the server doesn't have guaranteed 24/7 uptime.

It's also worth mentioning that using Shell Genie with GPT-3 requires using an API key, while using the Free Genie server does not.

You might also like: Use ChatGPT From The Command Line With This Wrapper


Install and use Shell Genie


Shell Genie can be installed using pipx, a tool to install and run python applications in isolated environments. Shell Genie requires Python 3.10 or newer, so make sure you're using this before continuing (e.g. it won't work on Ubuntu 20.04 or Debian Bullseye and older).

Install pipx from your Linux distribution's repositories:

  • Debian, Ubuntu and Linux distributions based on these (Linux Mint, Elementary OS, Pop!_OS, Zorin OS, etc.):
sudo apt install pipx

  • Fedora:
sudo dnf install pipx

  • Arch Linux / Manjaro:
sudo pacman -S python-pipx

  • openSUSE:
sudo zypper install python-pipx

Now all you have to do is use pipx to install Shell Genie:

pipx install shell-genie

Shell Genie should now be installed in ~/.local(for your user only). In case ~/.local/bin is not available in your PATH, add it. pipx can do this automatically for you – run pipx ensurepath, then open a new terminal window to use the new PATH.

To use Shell Genie, you'll need to configure it. So the first time you need to run it like this:

shell-genie init

This will prompt you to choose the backend you want to use (OpenAI GPT-3 or Free Genie), etc. If you select the OpenAI GPT-3 backend, you'll need to provide an API key. You can get one by creating an OpenAI account, then visit your account settings and click on API keys. Make sure you have sufficient credits in your OpenAI account to use it.

After the initial setup has finished, you can start using Shell Genie, like this:

shell-genie ask "<the command you want to run/generate, in plain english>"