CREDIT FOR THE ORIGINAL SCRIPT GOES TO https://github.com/0xacx/chatGPT-shell-cli
With the explosion of ChatGPT use, I decided to search around for a shell script that I could call from my terminal. After testing out different ones, I settled on this one.
I have modified and edited the hell out of it for my own personal use. It's got some image generation capabilities that I do not use often.
The original script saved all previous prompts to a file ~/.chatgpt_history
. But I found that after a few weeks of use, that file grew quite large. Mine was over 2,000 lines when I made this modification. It now creates a new daily file at ~/.chatgpt_history
with the format Y-%m-%d.md
.
Filename examples:
~/.chat_history/2023-08-24.md
~/.chat_history/2023-08-25.md
~/.chat_history/2023-08-26.md
I found this method better as I can now quickly "Live Grep" search with Neovim 👍
When prompting the first prompt of the day, this was the old output:
I made it so that it shows the current date file, and the number of prompts & lines for the day:
Each prompt is now also now saved for better readability.
I heavily use rofi (A window switcher, application launcher and dmenu replacement ) with greenclip (Simple clipboard manager to be integrated with rofi).
So I made all prompt responses piped out to xclip -selection clipboard
, so I can quickly and easily paste elsewhere.
Generated images are saved to ~/.chatgpt_history/images
folder with date stamp, and suffixed with an incrementing number count.
Filename examples:
~/.chat_history/images/2023-08-26_1.png
~/.chat_history/images/2023-08-26_2.png
~/.chat_history/images/2023-08-26_3.png
First get your own API key from https://platform.openai.com/account/api-keys
And add these 2 lines to .zshrc
.
export OPENAI_API_KEY=sk-**********************************
export PATH="/home/UserName/path/to/script/chat:$PATH"
Give your script the proper permissions.
chmod +x chat
curl (for API calls)
jq (JSON parser)
xclip (clipboard)
glow (markdown viewer)