Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/backus/ai.sh
Copilot for the terminal. Generate commands and preview them before running
https://github.com/backus/ai.sh
Last synced: 26 days ago
JSON representation
Copilot for the terminal. Generate commands and preview them before running
- Host: GitHub
- URL: https://github.com/backus/ai.sh
- Owner: backus
- Created: 2023-03-13T01:19:04.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-03-27T03:21:42.000Z (over 1 year ago)
- Last Synced: 2024-10-06T04:34:28.193Z (about 1 month ago)
- Language: Jupyter Notebook
- Size: 1.35 MB
- Stars: 58
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ai.sh
Copilot for the terminal. Generate commands and preview them before running.
## Demo
![demo](demo.gif)
## What's inside
Just run `ai 'what you want to do'` and the script will use [code-davinci-002 (AKA "Codex")][codex] to convert the prompt into (hopefully) runnable bash / zsh.
Under the hood, the tool uses [skim][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[codex]: https://help.openai.com/en/articles/6195637-getting-started-with-codex
[skim]: https://github.com/lotabout/skim## Dependencies and setup
This tool is written in pure bash, but it depends on a few programs being available:
* [bat](https://github.com/sharkdp/bat) for syntax highlighted code previews
* [skim](https://github.com/lotabout/skim) for the interactive UI for choosing if you want to run the code, copy it, or discard
* [openai-python](https://github.com/openai/openai-python) for the openai CLI
* [sd](https://github.com/chmln/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](https://github.com/backus/ai.sh/issues/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](https://github.com/jayhack/llm.sh)