Copilot for the terminal. Generate commands and preview them before running.
Just run ai 'what you want to do'
and the script will use code-davinci-002 (AKA "Codex") to convert the prompt into (hopefully) runnable bash / zsh.
Under the hood, the tool uses skim to provide a preview of the generated command, allowing you to choose to either (1) Run, (2) Copy, or (3) Discard the generated code.
I tried to calibrate the prompt this tool uses to try to do a few things:
- Generate the simplest command possible for the given prompt
- Try to annotate destructive commands (deleting files, killing processes, etc) with a leading
# destructive
comment
This tool is written in pure bash, but it depends on a few programs being available:
- bat for syntax highlighted code previews
- skim for the interactive UI for choosing if you want to run the code, copy it, or discard
- openai-python for the openai CLI
- sd for string manipulation
This tool uses the OpenAI CLI and therefore needs an active API key. It looks for a file in ~/.config/ai.sh/config
where the contents should just be OPENAI_API_KEY=sk-1234...
I hope it is obvious that you should exercise caution in running a bash script that uses AI to generate and run commands in your terminal. I've tried to make it sane, but use your best judgement and make sure you understand what you run.
I don't have any plans to make this work outside of macOS since I only use macs for development. That said, @agarrubio shared some tips in #3 on how to modify this script to work on Ubuntu so check out that issue if you want to modify for your own use.
- Thanks to Jay Hack for the original inspiration with his llm.sh