ubuntu への github Copilot in the CLI インストール方法

[github Copilot in the CLI](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-in-the-command-line) を ubuntu (私は WSL2) にインストールできたときのメモです。なんか lynx ブラウザ周りが微妙にむつかしかったのでメモします。

# gh のインストール
まずは gh というコマンドをインストールするみたいです。
```bash
(type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \
	&& sudo mkdir -p -m 755 /etc/apt/keyrings \
	&& wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
	&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
	&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
	&& sudo apt update \
	&& sudo apt install gh -y
```

# gh にログイン
```bash
gh auth login -wh github.com
```
ここで質問が来ますが、下記は適当に答えます:
```
? What is your preferred protocol for Git operations on this host? SSH
? Upload your SSH public key to your GitHub account?
? Title for your SSH key:
```
下記が表示されたら one-time code をコピーしてエンターキーを押します
```
! First copy your one-time code: XXXX-XXXX
Press Enter to open github.com in your browser...
```

ここで lynx がブラウザとして開きます。

```
github.com cookie: =xxxxxxxxxxx Allow? (Y/N/Always/neVer)
```
これに対しては `A` と答えます。

しばらくすると github のページが開くんですが、***こいつのモバイル認証時の ajax が動かなくてログインできない***ので、別の最近の GUI の Chrome ブラウザとかで https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Flogin%2Fdevice を開きます。

- Verify Session → ログインするアカウントを選びます
- Device Activation → 先ほどの `xxxx-xxxx` を入力する
- Authorize application → Authorize github ボタンを押す
- Congratulations, you're all set! → chrome を閉じる

ここで lynx の方に帰ってきて、

- lynx → `q` キー
- Are you sure you want to quit? (y)  → `y` キー

しばらく固まりますがおおらかに待つと
```
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
! Authentication credentials saved in plain text
✓ SSH key already existed on your GitHub account: /home/xxxx/.ssh/xxxxx.pub
✓ Logged in as koteitan
! You were already logged in to this account
```
のようなのが出て成功します。

# copilot のインストール

```bash
gh extension install github/gh-copilot
gh extension upgrade gh-copilot
```

これでインストール完了です。

## テスト
```bash
gh copilot
```
使い方が示されます。
```bash:
Your AI command line copilot.

Usage:
  copilot [command]

Examples:

$ gh copilot suggest "Install git"
$ gh copilot explain "traceroute github.com"


Available Commands:
  alias       Generate shell-specific aliases for convenience
  config      Configure options
  explain     Explain a command
  suggest     Suggest a command

Flags:
  -h, --help              help for copilot
      --hostname string   The GitHub host to use for authentication
  -v, --version           version for copilot

Use "copilot [command] --help" for more information about a command.
```
---
```bash
gh copilot explain gcc
```
gcc の説明がなされます
```bash
Welcome to GitHub Copilot in the CLI!
version 1.0.5 (2024-09-12)

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:

  gcc is a compiler for the C programming language. It is used to compile and link C
  source code files into executable binaries and libraries.

  • gcc is the command used to invoke the GCC compiler.
  • The command can include multiple source code files as arguments, which will be
  compiled and linked together.
  • Various flags can be used with gcc to control the compilation process:
    • -o output_file specifies the name of the output file.
    • -c compiles the source code files into object files without linking.
    • -Wall enables all warning messages.
    • -g includes debugging information in the compiled binary.
    • -I include_directory adds an include directory to the search path for header
    files.
    • -L library_directory adds a directory to the search path for libraries.
    • -l library_name links against a specific library during the linking phase.
    • -D macro_name=value defines a preprocessor macro with a specific value.
  • The exact behavior of gcc depends on the specific command-line arguments and options
  used.
```

以上。使い方とかは Google で調べてください。

cf. https://docs.github.com/ja/copilot/managing-copilot/configure-personal-settings/installing-github-copilot-in-the-cli#copilot-in-the-cli-%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB