CLI ChatGPT integration for discovering Linux commands or answering random ChatGPT queries.
Askgpt can be used as a stand-alone GPT CLI or plugged-in to zsh (or other shells) in order to act as your CLI assistant.
When configured as below, you can interact with ChatGPT from the command line, and either:
- Have it respond to a CLI-related question, putting the linux command in the queue for you to execute, or
- Respond to a general question (non-linux related)
Askgpt will attempt to recognize when your query is about a linux command and, when configured properly in zsh, will allow you to execute that command by just pressing enter.
Example:
zsh> ask how do I list all files including hidden
zsh> ls -a
To accept askgpt's response, press enter. To cancel, backspace over text or press CTRL-C.
If the query appears to be unrelated to a linux command, askgpt will just print the results.
You can force the general response by using ai
instead of ask
Example:
zsh> ai what is the highest mountain
The highest mountain in the world is Mount Everest.
zsh>
Some requests may require quoting the entire string, for instance, when using some punctionation (?,.$). To avoid this, just type ask
or ai
followed by ENTER. Then type string.
Example:
zsh> ai
ai: what are quotes(") for?
- Clone repository
pipx install ./askgpt
pipx uninstall askgpt
poetry install
poetry shell
python3 -m askgpt
OPENAI_API_KEY=[YOUR OPENAI API KEY]
export OPENAI_API_KEY
ASKGPT_PATH=~/Dev/askgpt
ask() {
if [ $# -eq 0 ]; then
echo "ask: \c"
read user_input
set -- $user_input
fi
local cmd=$(askgpt "$@")
# if askgpt returns NULL it is outside of the CLI domain
if [[ $cmd == NULL* ]]; then
print "Outside of CLI domain"
else
# Add output to zsh history
print -z $cmd
fi
}
ai() {
if [ $# -eq 0 ]; then
echo "ai: \c"
read user_input
set -- $user_input
fi
askgpt -q "$@"
}