Skip to content

Get ChatGPT to help you generate shell commands directly from your CLI

License

Notifications You must be signed in to change notification settings

tomoum/chatgpt-cli-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChatGPT-cli-helper

get chatGPT to help you generate shell commands directly from your CLI

Example usage: ai "list all python files in my current directory"

chatgpt_demo_v0 0 1

Pre-requisites

Tools

Required Installations:

  • sudo apt install python or brew install python (tested on 3.10.10)
  • pip install openai

Optional:

  • sudo apt install xclip

OpenAI API key

  1. go to https://platform.openai.com/account/api-keys and generate an API key
  2. create a file called .openai-key and place it in a folder called keys the root directory of the project. i.e keys/.openai-key

Note: You may need to provide your billing details for the openAI API to allow your requests. You can set a maximum dollar spend amount limit to something you can live with. 😄💸

Instructions

Step 1: For Everyone

Modify the constants found at the top of main.py file to your specific needs.

# keys folder in the root of the project with the api key in a file named `.openai-key`
API_KEY_LOCATION = Path("keys") / ".openai-key"
OS_VERSION = "ubuntu 20.04 running on wsl2"
SHELL_TYPE = "bash"

TODO: update docs with powershell and env variable update

Step 2: Depending on your Shell, OS and System

Bash on WSL2

  1. Add the snippet below to your ~./.bashrc file and update the path to your python script location mine is ~/.my_toolbox/chatgpt-cli-helper/src/main.py
function ai() {
    local ai_cmd=$(python ~/.my_toolbox/chatgpt-cli-helper/src/main.py "$1")
    echo "$ai_cmd"            # print the selected command
    echo "$ai_cmd" | clip.exe # add to clipboard in wsl2
    # optionally
    # printf "%s" "$ai_cmd" | xclip -selection clipboard # copy the command to
    # clipboard on non wsl linux os
    # printf "\033[G\033[K%s" "$ai_cmd" # place the command on the command line buffer
}

IMPORTANT:
Remember to relaunch your shell for changes to take effect or do source ~/.bashrc

About

Get ChatGPT to help you generate shell commands directly from your CLI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages