GitHub Copilot CLI¶
The GitHub Copilot CLI (Command Line Interface) is another way you can use Copilot for terminal help with commands. These include:
- Helping with explaining an unfamiliar command.
- Helping with suggesting a command that is right for the task you are doing.
The Copilot CLI is a great tool to use when you are working in the terminal and need help with a command or need a suggestion for a command to use.
For initial setup of Github Copilot CLI, you can follow the instructions.
There are two modes of using Copilot CLI which are explain
and suggest
. The following sections will go over using both modes.
Copilot CLI Explain¶
The explain
mode of Copilot CLI is used to get an explanation something that you can use within the terminal such as asking about a command or explaining how to use a command based on what you want to do.
Here is an example of using explain
mode to help with explaining conventional commits:
Prompt
gh copilot explain "Can you elaborate on how to do conventional commits for a git commit message
Alternatively you can run
gh copilot explain
without the prompt message and Copilot will ask you for the prompt anyways.
When the prompt is entered and ran, you should get a similar response to the one seen in this image.
The response I received gave me a simple high level explanation of what conventional commits are and how to use them. Alongside it provided an example of how a conventional commit message should look like.
Copilot CLI Suggest¶
The suggest
mode of Copilot CLI is used more to ask copilot to suggest a command that you prompt copilot for. This can be useful if you are not sure what command to use for a specific task.
suggest
has a few options for prompting copilot of suggestions. First we need to do is prompt Copilot to provide a suggestion to what we want to do.
Here is an example that prompts copilot to suggest a command to run for testing a golang project.
Prompt
gh copilot suggest "run tests for go project"
When the prompt is entered and ran, you will get the following options to choose from to give Copilot more context as seen in this image.
The following options are available to choose from:
gh command
- gh command context for suggestion prompted.git command
- git command context for suggestion prompted.generic shell command
- suggest a generic shell command for the prompt.
In the example case of trying to run tests for a go project, would be generic shell command
be best option.
Alternatively, we can set the target for the suggestion by using -t
flag in the command to avoid the prompt for context. Here is an example of how to do that:
Prompt
gh copilot suggest -t shell "run tests for go project"
Afterwards, Copilot will provide a suggestion for the command to run. Along with follow up actions for you to choose from.
Quick and simple, this option copies the suggested command to your clipboard. Allowing you to paste it into your terminal once you are done with the prompt.
Like in the explain
mode, this option will provide an explanation of the suggested command. This can be useful if you are not sure what the suggest command does or how it works.
As seen in the image explain
option provides a run down of the suggested command and the context of what it's doing or targeting.
Another simple option here, this will execute the suggested command in the terminal.
This option will require that you use --shell-out
or -s
flag to execute the command in the terminal using this method.
Alternatively, if you do not have flag set, Copilot will default to copying the command to the clipboard for you to use after the suggestion is complete.
This option will allow you to revise the prompt you gave Copilot to suggest a new command.
You can utilize this option if you want to add or change the prompt to get a different suggestions.
For example we can revise the prompt if we want to get more terminal output for the go test command we were suggested earlier:
Revisions
run tests for go project with more output in terminal
The revision gave us a new addition to the previous suggestion. If we are unsure of what the command does such as that -v
we can ask Copilot to explain the command to us as a follow up option.
Rate response
is a feedback option for Copilot to help improve the suggestions it provides. Feel free provide feedback to help improve Copilot suggestions.