> For the complete documentation index, see [llms.txt](https://manual.dxable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.dxable.com/1password/use-shell-plugins-to-switch-between-multiple-environments.md).

# シェルプラグインを使って複数の環境を切り替える

### **シェルプラグインを使って複数の環境を切り替える** <a href="#jg4zxdmldvuk" id="jg4zxdmldvuk"></a>

[1Password Shell プラグイン](https://developer.1password.com/docs/cli/shell-plugins/)を使うと、さまざまな環境のさまざまな資格情報セットをシームレスに切り替えられるため、環境間でのサインインやサインアウトに時間を費やす必要がありません。

例えば、開発環境のCreate業ディレクトリーにある開発用認証情報と、本番環境のCreate業ディレクトリーにある本番用認証情報を使い分けるようにTerraformシェルプラグインを設定できます。その後、いずれかのディレクトリーで Terraformコマンドを実行すると、Terraformプラグインは適切な認証情報を使って自動的に認証します。

### **ステップ 1：環境に合わせてディレクトリーを整理する** <a href="#zgubozsoj5gi" id="zgubozsoj5gi"></a>

各環境間でコンテキストを切り替えるためのシェルプラグインを設定する前に、プラグインで使うディレクトリーを環境ごとにグループ化します。

例えば、開発環境と本番環境の両方で Terraformシェルプラグインを使う場合は、次のようにディレクトリーを整理します。

![](/files/yWDPWaeZjgPKmozLg6RP)

### **ステップ 2：各環境ごとにデフォルトの資格情報を設定する** <a href="#rar9ufcdogpw" id="rar9ufcdogpw"></a>

環境別にディレクトリーを整理したら、各ディレクトリーとその全サブフォルダーで使うシェルプラグインのデフォルトの資格情報を設定できます。

1. Createした環境レベルのフォルダーの１つにディレクトリーを変更します。\
   例：\
   $ cd projects/production
2. 使いたい資格情報がSaveされている 1Password アカウントにサインインします。\
   $ op signin
3. 初期化するプラグインを選択するか、実行してop plugin init利用可能な全プラグインのリストから選択します。例えば、Terraformシェルプラグインを初期化するには、次のようにします。\
   $ op plugin init terraform
4. 環境に適した資格情報をインポートまたは選択します。
5. デフォルトの資格情報スコープとして、「Use automatically when in this directory or subdirectories」を選択します。
6. それぞれの資格情報を使用して、他の環境レベルのフォルダーでこのプロセスを繰り返します。

これにより、他のディレクトリー固有のデフォルトが設定されていない限り、各環境レベルのフォルダーで構成した資格情報が、そのフォルダー内の全てのサブフォルダーのデフォルトになります。

### **ステップ3：複数の環境でプラグインを使う** <a href="#ga3r4abxeka2" id="ga3r4abxeka2"></a>

全ての環境レベルのフォルダーにデフォルトの資格情報を設定すると、サインインまたはサインアウトすることなく、各環境のCreate業ディレクトリーでシェルプラグインを使えるようになります。

1. 環境のCreate業ディレクトリーを入力します。例えば、上記の例から開発環境にディレクトリーを変更するには、次のようにします。\
   $ cd \~/projects/development
2. その環境でジョブを実行します。\
   例:\
   $ terraform apply
3. 別の環境に切り替えます。例えば、本番環境に変更するには、次のようにします。\
   $ cd \~/projects/production
4. その環境でジョブを実行します。\
   $ terraform apply
5. 環境の利用を終了します。\
   $ op signout

シェルプラグインは、ユーザー側での操Createを必要とせずに、各環境の適切な資格情報を使ってて自動的に認証します。

### **さらに詳しく知るには** <a href="#id-1gmmp6aj7p7v" id="id-1gmmp6aj7p7v"></a>

* [1Password Shellプラグインを使い始める](https://developer.1password.com/docs/cli/shell-plugins/)
* [独自のシェルプラグインを構築する](https://developer.1password.com/docs/cli/shell-plugins/contribute/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.dxable.com/1password/use-shell-plugins-to-switch-between-multiple-environments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
