ずいぶん話題になっているChatGPTのビッグウェーブにちょっと乗っかっておこうと思い立ち、BashとVimでChatGPTが使える環境を整えたのでメモ
事前に必要な事 OpenAI Platformのサイトに行き、APIキーを生成しておく必要があります
また下記の通り、利用自体は料金がかかる場合もあるので自己責任でお願いします
OpenAI | Pricing 
あと、Python環境が必要です
Shell Shell GPT 
pip install shell-gpt とするだけです(Pythonの導入については本記事では割愛)
1 2 3 4 5 // インストール $ pip install shell-gpt // 実行 $ sgpt "terraformでS3バケットを作って" 
出力
1 2 3 4 5 6 7 8 9 10 11 12 13 14 はい、S3バケットを作成するためには、Terraformを使用することができます。 以下のようなTerraformコードを使用することができます。 provider "aws" {   region = "us-west-2" } resource "aws_s3_bucket" "example" {   bucket = "example-bucket"   acl    = "private" } このコードを使用すると、"example-bucket"という名前のS3バケットが作成されます。 ただし、AWSアカウントに必要な権限があることを確認してください。また、AWSプロバイダーのリージョンを適切に設定する必要があります。 
Vim CoderCookE/vim-chatgpt 
1 2 3 4 5 // openaiパッケージをインストール pip install openai // 環境変数CHAT_GPT_KEYにAPIキーを設定する export CHAT_GPT_KEY='(事前に取得したAPIキー)' 
当記事ではVim Plugを使用しています、ご自身の環境に合わせて下さい
1 2 // vim-chatgptプラグインをインストール Plug 'CoderCookE/vim-chatgpt' 
.vimrcに以下を追記
1 let g:chat_gpt_max_tokens=2000 
Vimで使ってみる
1 :Rewrite "terraformでubuntuイメージを起動するECSタスク定義を作って" 
出力
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Sure, here's the rewritten code snippet using Terraform to create an ECS task definition that launches an Ubuntu image: resource "aws_ecs_task_definition" "example" {   family                   = "example-task"   container_definitions    = <<DEFINITION [   {     "name": "example-container",     "image": "ubuntu",     "essential": true,     "command": [       "echo",       "Hello, World!"     ]   } ] DEFINITION } This creates a task definition with a single container called "example-container" that uses the Ubuntu image and runs the command "echo 'Hello, World!'" when it starts.