Skip to content

A command line tool to generate bash commands from natural language.

Notifications You must be signed in to change notification settings

liupeirong/bash-copilot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This is a command line tool that lets you type in natural language and generates bash commands which you can decide to run. It's inspired by the Codex Cli sample and has been refactored from deprecated Codex models to GPT models with chat completion APIs.

How to set it up?

You only need to set it up once.

Install Python and OpenAI

  1. Clone this repo to your machine, to a folder <REPO_ROOT>. All files mentioned below are relative to this root.
  2. Set the environment variables OPENAI_API_URL and OPENAI_API_KEY to point to your Azure OpenAI Service.
  3. Edit config.ini to configure your Azure OpenAI deployment and model.
  4. Install Python 3.8+.
  5. Install Python modules by running pip install -r requirements.txt. This copilot has dependency on openai only.

Configure bash

  1. Set the environment variable BASH_COPILOT_PATH in scripts/bash_setup.sh to your <REPO_ROOT>.
  2. Adjust the #! path for bash in the first line of all .sh files in the scripts folder.
  3. Adjust the #! path for python in the first line of src/main.py.
  4. Run scripts/bash_setup.sh, then open a new bash console.

How to run?

In a bash console, type in # followed by your question in natural language in one line. Hit Ctrl + G when you are done.

If there's no error, Azure OpenAI will generate a bash command. If you like the command, hit enter to run it. Otherwise hit Ctrl + C to quit.

Memory

User/AI Q&A history is stored in current_context.txt. When this copilot starts, it will load this history as its memory.

  • If the total number of tokens is beyond the specified max number of tokens, earlier history will be deleted.
  • You can run the commands # show context, # clear last context, or # clear context to interact with this memory.

How to customize for your use case?

  1. You can customize system prompt in contexts/system_prompt.txt.
  2. You can customize few-shot examples in contexts/examples.txt.

About

A command line tool to generate bash commands from natural language.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published