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 punctuation (?,.$). To avoid this, just type ask or ai followed by ENTER. Then type string.
Example:
zsh> ai
ai: what are quotes(") for?
Clone the repository and install with pipx (recommended):
git clone https://github.com/steverhall/askgpt.git
cd askgpt
pipx install .Copy or symlink askgpt.plugin.zsh to a directory in your fpath, or source it directly in your .zshrc:
# Add this to your ~/.zshrc
source /path/to/askgpt/askgpt.plugin.zshClone or symlink the plugin into your custom plugins directory, then add askgpt to your plugins list in .zshrc:
git clone https://github.com/steverhall/askgpt.git $ZSH_CUSTOM/plugins/askgpt
# In your .zshrc:
plugins=(... askgpt)Add this to your .zshrc:
zinit light steverhall/askgptif (!(Test-Path -Path $PROFILE)) {
New-Item -Type File -Path $PROFILE -Force
}
notepad $PROFILEAdd the following contents to your PowerShell profile:
function ask {
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Prompt
)
if (-not $Prompt) {
$Prompt = Read-Host "ask"
} else {
$Prompt = $Prompt -join " "
}
$cmd = askgpt --prompt "$Prompt"
if ($cmd -eq "NULL") {
Write-Host "No results found"
} else {
# Place command in command line for review (simulate with clipboard)
Set-Clipboard $cmd
Write-Host "Command copied to clipboard. Paste and press Enter to run."
}
}
function ai {
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Prompt
)
if (-not $Prompt) {
$Prompt = Read-Host "ai"
} else {
$Prompt = $Prompt -join " "
}
askgpt --ai --prompt "$Prompt"
}Then, as admin:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSignedEdit askgpt.plugin.zsh or set in your .zshrc:
export OPENAI_API_KEY=[YOUR OPENAI API KEY]Askgpt supports configuration through a TOML file located at $HOME/.config/askgpt/askgpt.toml.
You can set default values for model and temperature:
model = "gpt-4"
temperature = 0.8Command line arguments will override config file values:
# Uses model and temperature from config file
askgpt --prompt "Hello"
# Overrides config file model
askgpt --model "gpt-3.5-turbo" --prompt "Hello"
# Overrides config file temperature
askgpt --temperature 0.3 --prompt "Hello"pipx uninstall askgptThe plugin provides these functions:
ask # Query for a CLI command and queue it for execution
ai # Query for a general answer