Code Monkey home page Code Monkey logo

chatgpt-cli-helper's Introduction

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

chatgpt-cli-helper's People

Contributors

tomoum avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.