LoginSignup
45
22

コマンド忘れがち → GitHub Copilot in the CLI を使ってみよう

Last updated at Posted at 2023-12-10

「◯◯するコマンド、何だったっけ...」と、たまになりませんか?
この記事では、そういった時に役立ちそうな 「GitHub Copilot in the CLI※」 を使ってみたいと思います。(※2023年11月8日 パブリックベータ版の提供開始が発表されました)

GitHub Copilot in the CLI とは

CLI(Command Line Interface)上でコマンド実行を補助するツールです。
現時点、できることは大きく2つです。

  • 適切なコマンドを提案してもらう
  • コマンドについて説明してもらう

セットアップ

前提条件

  • GitHub アカウントの所有
  • GitHub Copilot のサブスクリプションに登録済(有料)
    • 登録はGithubの設定画面から。初登録の場合、30日間無料で使えるようになっています(記事執筆時点)
  • GitHub CLI インストール済
  1. コマンド操作ツールを開き、GitHub に ログインします
gh auth login
  1. Copilotの拡張機能をインストールします
gh extension install github/gh-copilot

以上、セットアップ完了です。

使い方その① コマンドを提案してもらう

下記を入力すると対話が始まります。

gh copilot suggest

はじめにコマンドの種類は何なのか質問されます。

? What kind of command can I help you with?  [Use arrows to move, type to filter]
> generic shell command //シェルコマンド
  gh command //GitHub CLI コマンド
  git command //Git コマンド

shell commandを選択しました。
すると、何がしたいのか質問されますので回答します。

? What would you like the shell command to do?
> フォルダ名がtest-copilotのフォルダを探して、それをデスクトップに移動させたい

数秒後、回答がきました。

Suggestion:                                                                    
  find ~/ -type d -name "test-copilot" -exec mv {} ~/Desktop/ \;  
  
? Select an option  [Use arrows to move, type to filter]
> Copy command to clipboard //クリップボードにコピー
  Explain command //説明をしてもらう
  Revise command //入力を訂正
  Rate response //遅いと報告
  Exit  //終了

あとは、Suggestionが適切かを見て、よければ Copy して Exit します。
gh copilot suggest 何かやりたいことを入力すると、対話無しで、直接提案をもらうこともできます。

使い方その② コマンドについて説明してもらう

下記を入力すると対話が始まります。

gh copilot explain

以下では、例として mkdirの説明をしてもらってみました。

? Which command would you like to explain?
> mkdir

数秒後に回答がきました。

Explanation:                                                                   
  • mkdir is used to create a new directory.                                  
    • There are no flags used in the provided command. 

はい、ちゃんと回答してくれているようです。
gh copilot explain コマンド名と入力すると、対話無しで、直接説明をもらうこともできます。

まとめ

「GitHub Copilot in the CLI」を使って、コマンドの提案や説明をしてもらいました。
シンプルで対話的に進められ、便利なツールだなと思いました。
ただ、最低限のコマンドや頻繁に使うコマンドは覚えておくに越したことはありませんね:rolling_eyes:
Copilot界隈は、より進化していくと思うので今後に期待です。

最後に

株式会社HRBrainでは現在メンバー募集中です!:muscle:
カジュアル面談をしていますので先ずは話してみましょう:wave:
採用サイトはこちらです!:runner:

45
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
45
22