This ZSH completion script enhances your command line interface by providing auto-completion for the sgpt
command, part of the Shell GPT suite. It supports all subcommands and their options, significantly improving efficiency and reducing the need for memorizing syntax.
-
Download the Completion Script
You can download the_sgpt
script directly using the following command:mkdir -p $HOME/.zsh_completions wget -O $HOME/.zsh_completions/_sgpt https://gist.githubusercontent.com/obeone/dc66f2ca40b8254edab61ac50cdec0f3/raw/_sgpt.zsh
-
Add to ZSH Fpath
Ensure that the script is in one of the directories listed in yourfpath
. You can view your currentfpath
with:echo $fpath
To add a new directory to your
fpath
, include the following line in your.zshrc
:fpath=($HOME/.zsh_completions $fpath)
-
Source the Completion Script
To enable the completion script, restart your ZSH session or source your
.zshrc
file if you haven't done so since updating itsource ~/.zshrc
If you use Oh My Zsh, you can reload it with
omz reload
.ZSH should automatically source all completion scripts in your
fpath
when starting a new shell session. Ensure the script is named correctly as_sgpt
.
Simply type sgpt
followed by a space and a -
, then press tab
to see available subcommands and options. For example:
sgpt -[tab] # Lists all subcommands
sgpt --model [tab] # Will propose available models
- The completion of the role was bugged; it indicated .json at the end of role and it was not compatible with the expected arguments. The extension is now correctly filtered; however, if you have been impacted by the problem, you have to manually delete the existing cache of roles :
rm ~/.cache/sgpt_roles
- Removing caches on chats, it was impossible to detect their creation of a new chat and therefore invalidate this cache. It is still retained on roles, even if the same defect is present. Because roles, to me, do not change every hours.
The completion script for sgpt
was primarily generated using a custom GPT model I created named ZSH Expert (you need ChatGPT Plus to use it).
This model specializes in creating ZSH completion scripts by analyzing the --help
outputs of various commands. Here's the process:
-
Generating Completion Logic:
I provided the--help
outputs of thesgpt
command to ZSH Expert, which then generated the necessary ZSH completion logic, including handling of subcommands and options. -
Validation and Iteration:
The script was tested iteratively to catch any issues with command completion, especially around new or complex command options. Feel free to report any issues to help improve the script further.
You can view the entire creation process and the discussions that led to the final script in this chat history.
- ZSH Expert (ChatGPT Custom GPT, did almost all the job)
- obeone (Guiding and testing)
Distributed under the MIT License.