https://docs.github.com/ja/copilot/github-copilot-chat/using-github-copilot-chat-in-your-ide
GitHub CopilotのCLI版です。
2023年12月5日現在パブリックベータで公開されています。
インストール
gh auth login
gh extension install github/gh-copilot
gh extension upgrade gh-copilot
使い方
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.explain suggest の2つコマンドがあるので、それぞれ見ていきます。
gh copilot explain コマンドについて解説してもらう
gh copilot explain “common”のように入力するとコマンドについての解説をしてくれます
gh copilot explain ls? 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 0.5.3-beta (2023-11-09)
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.
Explanation:
• ls is used to list files and directories in the current directory. • If no arguments are provided, it lists the files and directories in the current directory. • It displays the names of the files and directories in a columnar format. • It does not show hidden files and directories by default.gh copilot explainを実行することで、対話的に入力することもできます。
gh copilot explainWelcome to GitHub Copilot in the CLI! version 0.5.3-beta (2023-11-09)
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 improv ? Which command would you like to explain?
jq 'walk(if type == "object" and has("rawSql") then .rawSql |= gsub("\r|\n"; " ") else . end)'
Explanation:
The provided command is using the jq command-line JSON processor. Here is a breakdown of the command:
• Use the jq command-line JSON processor. • walk is a built-in function in jq that traverses the input data recursively. • if type == "object" and has("rawSql") then .rawSql |= gsub("\r|\n"; " ") else . end is the conditional expression that is applied to each element during the traversal. • type == "object" checks if the current element is an object. • has("rawSql") checks if the object has a key named "rawSql". • |= is the in-place update operator in jq. • gsub("\r|\n"; " ") is a string manipulation function that replaces all occurrences of carriage return and newline characters with a single space. • else . end is the "else" clause that returns the original element if the conditions are not met.
Please note that the provided command might be part of a larger script or pipeline, and its functionality depends on the input data structure and intention.日本語で解説してもらいたい気持ちになりますね…
簡単なコマンドの説明ならやってくれました。
gh copilot explainWelcome to GitHub Copilot in the CLI! version 0.5.3-beta (2023-11-09)
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.
? Which command would you like to explain?
> 日本語で "ls" の説明
Explanation:
• ls はディレクトリやファイルのリストを表示するコマンドです。 • -a オプションは、隠しファイルを含めた全てのファイルやディレクトリを表示します。 • -l オプションは詳細な情報を含む長い形式で表示します。 • -r オプションはリストを逆順に表示します。 • -t オプションは最終更新時刻に基づいてリストをソートして表示します。少しコマンドが長くなると、プロンプトは認識されませんでした。
gh copilot explainWelcome to GitHub Copilot in the CLI! version 0.5.3-beta (2023-11-09)
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.
? Which command would you like to explain?
> 日本語で find / -name "*.pdf" -exec mv {} ~/Downloads/ \; を説明
Explanation:
• find / is used to search for files in the root directory. • -name "*.pdf" filters the search to files that have the extension .pdf. • -exec mv {} ~/Downloads/ ; executes the mv command for each found file, moving it to the ~/Downloads/ directory. • {} represents the file name that is passed as an argument to the mv command. • ; marks the end of the -exec statement.gh copilot suggest コマンドの提案を受ける
自然言語でやりたいことを入力すると、実行すべきコマンドを提案してくれます。
gh copilot suggestWelcome to GitHub Copilot in the CLI! version 0.5.3-beta (2023-11-09)
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.
? What kind of command can I help you with? [Use arrows to move, type to filter]
> generic shell command
gh command
git command実行すると、どのカテゴリのコマンドを生成するのかを聞かれます。
generic shell command(汎用シェルコマンド)を選択してみます。
? What would you like the shell command to do?
> pdfファイルを探してdownloadへ移動する
Suggestion:
find . -name "*.pdf" -exec mv {} download/ ;
? Select an option [Use arrows to move, type to filter]
> Copy command to clipboard
Explain command
Revise command
Rate response
Exit選択すると、 find . -name "*.pdf" -exec mv {} download/ ; というコマンドを提案してくれました。
提案されたコマンドについてのアクションを選択できます。
Copy command to clipboard: クリップボードへコピー
Explain command: コマンドを説明してもらう
Revise command: コマンドを修正する。コマンドの修正指示を自然言語で行えます
Rate response: 応答を評価できます
Exit: 終了
最後に
GitHub Copilot CLIを使ってみました。
自分が作ったコマンド(プロジェクトのpackage.jsonに書かれたコマンドなど)はサジェストしてくれないみたいなのは残念。
とはいえ、CLIでやりたいことやgitコマンドの提案を受けられるのは便利なので、使っていきたいです。
shwld