get chatGPT to help you generate shell commands directly from your CLI
Example usage: ai "list all python files in my current directory"
Required Installations:
sudo apt install python
orbrew install python
(tested on 3.10.10)pip install openai
Optional:
sudo apt install xclip
- go to https://platform.openai.com/account/api-keys and generate an API key
- create a file called
.openai-key
and place it in a folder calledkeys
the root directory of the project. i.ekeys/.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. 😄💸
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
- 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 dosource ~/.bashrc