Mooの技術メモ

技術的なメモ中心。

Windows TerminalにAnaconda Powershell Promptを追加してみた

はじめに

Windows Terminalを使うとモダンな開発環境を使いこなしていそうで格好いいのでインストールした。Windows Terminalを使うと、複数のターミナルを一つに集約できるようだ。

自分は同時に複数のターミナルを開くことはほぼ無いが、きっとハイレベルな技術者はPowershell、Azure Cloud Shell、WSLなどを同時に使うので、個別に立ち上げているとウィンドウが多すぎて使いにくいのだろう。

早速インストールした後、設定を開いてみたらかなり自由にカスタマイズできそうだったのでAnaconda Powershell Promptを追加しようとした。

しかし、若干ハマったため将来の自分のためにもメモとしてブログに書き残しておく。

インストール

Windows Terminalはマイクロソフトストアからインストールできる。

f:id:hiromoooo:20210105063827p:plain

ストアアプリでwindows terminalを検索してインストールする。

f:id:hiromoooo:20210105064352p:plain

設定方法

以下のステップで実施した。

  1. 設定ファイルを開く
  2. Powershellの設定をコピペ
  3. コピペした設定をもとにAnaconda Powershell Promptを開くように修正

1. 設定ファイルを開く

Windows Terminalを起動し、タブの横の下向きの矢印みたいなアイコンをクリックするとドロップダウンメニューを展開できる。

設定をクリックすると設定ファイルがメモ帳で開かれる。

f:id:hiromoooo:20210105080056p:plain

2.Powershellの設定をコピペ

以下画像のようにJSONでプロファイルが設定されているので、Powershellの設定部分をコピペしてリストの要素を一つ増やす。

f:id:hiromoooo:20210105073146p:plain

3.コピペした設定をもとにAnaconda Powershell Promptを開くように修正

Stack Exchangeのスレッドを参考に以下の通り設定した。公式ドキュメントはこちら

  • guid:
    • 一意の識別子として使用。PowershellNew-GUIDコマンドで生成しコピペ。一応補足に生成結果の画像を載せておく
  • name:
    • タブに表示する名称。今回は「Anaconda Powershell Prompt」にした
  • commandline:
  • hidden:
    • falseのまま変更しない。trueにするとドロップダウンに表示されなくなる
  • icon:
    • 新たにキーを追記して設定。ドロップダウンに表示するアイコン画像のパス。Pythonのアイコンにした。

修正結果は以下のような感じになる。

{
                "guid": "{01ebb42e-95d1-4e22-8fc2-df6a24d399fe}",
                "name": "Anaconda Powershell Prompt",
                "commandline": "powershell.exe -ExecutionPolicy ByPass -NoExit -Command \"& 'C:/Users/[user]/Miniconda3/shell/condabin/conda-hook.ps1' ; conda activate 'C:/Users/[user]/Miniconda3' \"",
                "hidden": false,
                "icon": "C:/Users/user/Documents/others/python-logo.png"
}

設定ファイルを保存し、Windows Terminalを開くとAnaconda Powershell Promptが使えるようになっている。

f:id:hiromoooo:20210105075326p:plain

補足

guidについて

Powershellで生成。適当でもいいらしい。

f:id:hiromoooo:20210105081300p:plain

commandlineのパスについて

以下の画像のとおりAnaconda Powershell Promptのファイルの場所へ飛んで、プロパティからコピペすれば良い。

f:id:hiromoooo:20210105074818p:plain

f:id:hiromoooo:20210105074841p:plain

ただし、余計な部分は削除、連結をバックスラッシュに変更、パス中のダブルクオーテーションをエスケープした。

設定完了後のプロファイル部分を抜粋して以下にコピペしておく。

    // A profile specifies a command to execute paired with information about how it should look and feel.
    // Each one of them will appear in the 'New Tab' dropdown,
    //   and can be invoked from the commandline with `wt.exe -p xxx`
    // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "Command Prompt",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{01ebb42e-95d1-4e22-8fc2-df6a24d399fe}",
                "name": "Anaconda Powershell Prompt",
                "commandline": "powershell.exe -ExecutionPolicy ByPass -NoExit -Command \"& 'C:/Users/[user]/Miniconda3/shell/condabin/conda-hook.ps1' ; conda activate 'C:/Users/[user]/Miniconda3' \"",
                "hidden": false,
        "icon": "C:/Users/hnaka/Documents/others/python-logo.png"
            },
        ]
    }