Skip to content
/ ai.sh Public

Copilot for the terminal. Generate commands and preview them before running

Notifications You must be signed in to change notification settings

backus/ai.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ai.sh

Copilot for the terminal. Generate commands and preview them before running.

Demo

demo

What's inside

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:

  1. Generate the simplest command possible for the given prompt
  2. Try to annotate destructive commands (deleting files, killing processes, etc) with a leading # destructive comment

Dependencies and setup

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

Config

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...

Warranty

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.

Linux

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.

Credits

  • Thanks to Jay Hack for the original inspiration with his llm.sh

About

Copilot for the terminal. Generate commands and preview them before running

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published