Github has an official CLI tool to enhance our command-line experience. From working with repositories, issues, and gists, to name a few of the features. I am a OhMyZsh user on macOS and wanted to take advantage of the command completion it offers.
In this short post, we’ll go through the steps necessary to get command completion working with our OhMyZsh installation.
Installing the GitHub CLI
On macOS, I suggest using Homebrew to install the GitHub CLI. Homebrew will help keep our installation up to date.
brew install gh
Creating The Completion File
The GitHub CLI supports multiple shells, but we need to generate one specifically for ZSH. From our terminal, we need to run the following command.
gh completion --shell zsh > $ZSH_CUSTOM/plugins/gh.zsh
Performing the command will generate the completion lists for ZSH right inside the OhMyZsh plugin directory. This directory is automatically loaded every time we start our shell. Note, we may need to type in our admin password to write to this directory.
Updating .zshrc
The next step is to tell OhMyZsh about our new command completion file. We need to open our .zshrc
file by running the following command.
open ~/.zshrc
The .zshrc
file should open in an editor, or macOS should prompt us to pick an editor. At the bottom of the file, add the following line.
# github
compctl -K _gh gh
We can restart our terminal now, and code completion should work.
Testing Out The Completion
We can type gh
followed by a tab, which should list all the commands.
I hope this post was helpful, and thanks for reading.