This ZSH completion script enhances your command line interface by providing auto-completion for the ollama
command, part of the Ollama 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_ollama
script directly using the following command:mkdir -p $HOME/.zsh_completions wget -O $HOME/.zsh_completions/_ollama https://gist.githubusercontent.com/obeone/9313811fd61a7cbb843e0001a4434c58/raw/_ollama.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_ollama
.
Simply type ollama
followed by a space and a -
, then press tab
to see available subcommands and options. For example:
ollama [tab] # Lists all subcommands
ollama serve --[tab] # Will propose all available options for the `serve` command
The completion script for ollama
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 theollama
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. This was the first completion script I created with ZSH Expert while developing it, and the discussion was really laborious! 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. It was the first completion script I made during the development of ZSH Expert. So, naturally, the discussion was very long and tedious.
- ZSH Expert (ChatGPT Custom GPT, did almost all the job)
- obeone (Guiding and testing)
Distributed under the MIT License.
Nice, it works like a charm!
Any plan to publish it as official plugin ?
I can help if needed
Regards