GitHub Copilot in the CLI というものがあるのを教えてもらったので試してみました
GitHub Copilot in the CLI は、チャットのようなインターフェイスをターミナルに提供し、コマンド ラインについて質問できるようにします。 GitHub Copilot に質問すると、コマンドの提案または指定されたコマンドの説明が提供されます。
GitHub Copilot in the CLI は、自然言語処理と機械学習を組み合わせて質問を解析し、回答を提供します。 このプロセスは、いくつかの手順に分けることができます。
GitHub Copilot in the CLI について - GitHub Docs
注意事項
公式から引用しておきます
最新情報は公式を見に行ってください
この機能を使用できるユーザーについて
GitHub Copilot Business または GitHub Copilot Enterprise サブスクリプションを持つ組織または企業のオーナーは、組織または企業内のユーザーに対して GitHub Copilot in the CLI へのアクセスを許可するかどうかを決定できます。
GitHub Copilot Individual サブスクリプションをお持ちの場合は、GitHub Copilot in the CLI にアクセスする事ができます。
Copilot in the CLI を使用するには、アクティブな GitHub Copilot サブスクリプションが必要です。 詳しくは、「GitHub Copilot の課金について」を参照してください。
Copilot in the CLI を使用するには、GitHub CLI がインストールされている必要があります。 GitHub CLI のインストール手順については、GitHub CLI リポジトリを参照してください。
CLI での GitHub Copilot の使用 - GitHub Docs
ざっくり手順
- GitHub CLI のインストール
- Copilot in the CLI 拡張機能のインストール
- GitHub Copilot in the CLI を使ってみる
GitHub CLI のインストール
GitHub Copilot in the CLI を利用するには、まず GitHub CLI がインストールされている必要があります。
GitHub CLI は、GitHub のリポジトリを管理するためのツールです。
インストールは非常に簡単で、Windows の場合は winget でインストールできます
1
|
winget install --id GitHub.cli
|
cli/cli: GitHub’s official command line tool
次に、GitHubアカウントでの認証を行うため、gh auth login
コマンドを実行します
1
2
3
4
5
6
7
8
9
10
11
12
|
PS C:\Users\kento> gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser
! First copy your one-time code: XXXX-XXXX
Press Enter to open github.com in your browser...
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as NakayamaKento
|
これにより、GitHub CLIを使用する準備が整います。
2. Copilot in the CLI 拡張機能のインストール
以下のコマンドを実行するだけです
1
|
gh extension install github/gh-copilot
|
これで準備は完了です
3. GitHub Copilot in the CLI を使ってみる
公式にあったサンプルを試してみました
sudo apt-get の説明をしてもらってます
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
PS C:\Users\kento> gh copilot explain
? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries.
> Yes
Welcome to GitHub Copilot in the CLI!
version 1.0.1 (2024-03-22)
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?
? Which command would you like to explain?
> sudo apt-get
Explanation:
• sudo is used to run a command with elevated rights, typically as the superuser.
• apt-get is the command-line tool for managing packages on Debian-based systems.
• It is used to install, upgrade, and remove software packages.
• It can also be used to update the package lists from the repositories.
• Common flags used with apt-get include:
• install - installs one or more packages.
• remove - removes one or more packages.
• update - updates the package lists from the repositories.
• upgrade - upgrades all installed packages to their latest versions.
• dist-upgrade - upgrades packages, handling dependencies intelligently.
• search - searches for packages matching a given pattern.
• show - displays detailed information about a package.
• autoremove - removes automatically installed packages that are no longer needed.
• clean - clears out the local repository of retrieved package files.
• purge - removes a package along with its configuration files.
|
ブラウザを立ち上げて検索をしなくても ターミナルで調べ物が完結しそうです
次にコマンドの提案をしてもらいました
「Windows OS でルート情報を知りたい」場合を想定しています
レスポンス速度も含めてみてもらいたかったので、動画にしてみました
ブラウザを開いて調べる or Copilot に聞く よりもターミナルで完結するのがメリットっぽい
ちなみに日本語でも動作はします
まとめ
GitHub Copilot in the CLI はブラウザを立ち上げたり、検索したりするのに比べると簡単に調べ物ができました
現状はコマンドに関する説明、提案だけなのでスクリプト生成をするときなどは Visual Studio Code などの Copilot chat の方が使いやすいかなって印象です
参考