others-How to use GitHub copilot cli to boost your performance in command line environment?
1. Overview
The GitHub copilot cli
is a command line tool to boost your performance in command line environments. You can chat in command line now!
To use this tool, you should:
- Have an active subscription of GitHub Copilot
- Have GitHub CLI installed on your computer
Then you can install the GitHub Copilot Cli
by following this article.
Before its working on your computer, you must login:
gh auth login
Then you can install GitHub Copilot Cli
:
gh extension install github/gh-copilot
To upgrade it, you can :
(base) ➜ gh extension upgrade gh-copilot
[copilot]: already up to date
✓ Successfully upgraded extension
To view all its options, you can:
(base) ➜ ~ gh copilot --help
Your AI command line copilot.
Usage:
copilot [command]
Examples:
$ gh copilot suggest "Install git"
$ gh copilot explain "traceroute github.com"
Available Commands:
config Configure options
explain Explain a command
suggest Suggest a command
Flags:
-h, --help help for copilot
-v, --version version for copilot
Use "copilot [command] --help" for more information about a command.
(base) ➜ ~
To change the options of GitHub Copilot Cli
, you can:
(base) ➜ ~ gh copilot config
? What would you like to configure?
> Optional Usage Analytics
? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries.
> No
? What would you like to configure?
> Exit
2. Explain commands
As the name shown, the gh copilot explain
command can explain the command you provided at details. Here are some examples.
2.1 Explain simple command
(base) ➜ ~ gh copilot explain 'telnet'
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
Explanation:
telnet is a command-line tool used for interactive communication with remote systems using the Telnet
protocol. It allows you to establish a TCP/IP connection to a specific remote host and port, and then
interact with the remote system by sending and receiving text-based data.
(base) ➜ ~
Let’s add some options to it:
(base) ➜ ~ gh copilot explain 'curl -vvv'
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
Explanation:
• curl is used to issue web requests, e.g. download web pages.
• -vvv is a flag used to increase the verbosity level of the command,
providing more detailed information about the request and response.
Good job.
2.2 Explain complicated command
Now let’s add some complicated pipes to the command:
(base) ➜ ~ gh copilot explain
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
? Which command would you like to explain?
> cat xx.csr | base64 | tr -d ‘\n’
Explanation:
• cat xx.csr prints the contents of the file xx.csr to the standard output.
• base64 encodes the input data as base64.
• tr -d '\n' removes any newline characters from the input.
(base) ➜ ~
Now give it a very complicated command:
(base) ➜ ~ gh copilot explain
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
? Which command would you like to explain?
> `find . -type f -name "*.conf" -exec grep -wH "aaa" {} +`
Explanation:
• find . searches for files and directories starting from the current
directory.
• -type f specifies that we are only interested in files, not directories.
• -name "*.conf" filters the search to files with the extension .conf.
• -exec grep -wH "aaa" {} + executes the grep command on each file found.
• grep -wH "aaa" searches for the exact word "aaa" in the file.
• -w matches whole words only.
• -H prints the file name along with the matching line.
• {} represents the file name that find finds.
• + indicates the end of the -exec command and that multiple file names
can be passed to grep at once.
Very good.
3. Suggest commands
Apart from explaining commands, GitHub Copilot Cli
can also suggest commands to do some jobs. Here are some examples:
3.1 Suggest simple commands
(base) ➜ ~ gh copilot suggest
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
? What kind of command can I help you with?
> generic shell command
? What would you like the shell command to do?
> how to compress files as tar.gz
Suggestion:
tar -czvf archive.tar.gz files/
? Select an option [Use arrows to move, type to filter]
> Copy command to clipboard
Explain command
Revise command
Rate response
Exit
Another one:
(base) ➜ ~ gh copilot suggest
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
? What kind of command can I help you with?
> generic shell command
? What would you like the shell command to do?
> How to list files using ls and sort them by name
Suggestion:
ls | sort
? Select an option [Use arrows to move, type to filter]
> Copy command to clipboard
Explain command
Revise command
Rate response
Exit
3.2 Suggest complicated commands
Now , let’s add some complication:
(base) ➜ ~ gh copilot suggest
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
? What kind of command can I help you with?
> generic shell command
? What would you like the shell command to do?
> How to replace some text in a file using sed
Suggestion:
sed 's/old_text/new_text/g' file.txt
Another one:
(base) ➜ ~ gh copilot suggest
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
? What kind of command can I help you with?
> generic shell command
? What would you like the shell command to do?
> how to copy local directory files recursively to remote machine and the port is not 22
Suggestion:
rsync -avz -e "ssh -p <port>" /path/to/local/directory user@remote:/path/to/remote/directory
Good job.
3.3 Suggest git commands
GitHub Copilot Cli
can also suggest git
commands, here are some examples:
(base) ➜ ~ gh copilot suggest
Welcome to GitHub Copilot in the CLI!
version 0.5.4-beta (2024-01-04)
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
? What kind of command can I help you with?
> git command
? What would you like the git command to do?
> How to add local git repository to remote repo?
Suggestion:
git remote add origin <remote_repository_url>
Very good.
4. Conclusion
To summarize, the GitHub Copilot Cli
is a command-line ‘AI’ tool which can help you to quickly solve command line problems. But it lacks some chat-history capability – that is it can only suggest or explain one command at a time, if you want more, you must open another command. It’s a good try in command line I think.