4

OhMyZsh GitHub CLI Command Completion

 3 years ago
source link: https://khalidabuhakmeh.com/ohmyzsh-github-cli-command-completion
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
December 1, 2020

OhMyZsh GitHub CLI Command Completion

OhMyZsh GitHub CLI Command Completion
Photo by Khalid Abuhakmeh

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.

github cli in terminal with zsh

I hope this post was helpful, and thanks for reading.

Tags: terminal

Khalid Abuhakmeh's Picture

About Khalid Abuhakmeh

Khalid is a product designer, traveler, respected community member, and open source contributor.

Comments

comments powered by Disqus


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK