A quick step by step guide to get AI powered suggestions and explanations, using Github Copilot, in your zsh powered terminal.

This will require access to Github Copilot, it is available for free for students. This guide also assumes you’re using zsh.

Step 1 - Installing gh & gh-copilot

As you may know, Github maintains a pretty nice CLI cli/cli, they also maintain an extension, github/gh-copilot, which let’s you interact with the Copilot LLM using terminal commands.

  • On macOS:
brew install gh
  • On Arch:
pacman -S github-cli

For other operating systems, follow the install instructions in the cli/cli repo.

Once installed, you’ll have to authenticate:

gh auth login --web

Next, to install the gh-copilot extension:

gh extension install github/gh-copilot --force

You can try it out with:

gh copilot suggest ...
gh copilot explain ...

Don’t forget to update the gh-copilot extension with gh extension upgrade --all from time to time.

Step 2 - Installing the zsh-gh-copilot plugin

To be able to easily bind the suggest and explain subcommands to a key combination, you’ll need to install the loiccoyle/zsh-gh-copilot plugin.

This process will depend on the zsh plugin manager you use. For example, for zplug, add the following to your .zshrc file:

zplug "loiccoyle/zsh-github-copilot"

I’ll encourage you to check out the README instructions for your plugin manager of choice.

This plugin will register two new zle keymaps, zsh_gh_copilot_suggest and zsh_gh_copilot_explain.

Step 3 - Binding explain & suggest

The final step is to bind the newly registered keymaps to keys. Simply add the following to your .zshrc:

  • On macOS:
bindkey '»' zsh_gh_copilot_explain  # bind Option+shift+\ to explain
bindkey '«' zsh_gh_copilot_suggest  # bind Option+\ to suggest
  • On Linux:
bindkey '^[|' zsh_gh_copilot_explain  # bind Alt+shift+\ to explain
bindkey '^[\' zsh_gh_copilot_suggest  # bind Alt+\ to suggest

And you’re all done, just open up a new terminal, type out a query or a command and hit the appropriate key bind.