2
3

More than 3 years have passed since last update.

Windows Terminalで色やフォントや画面サイズを設定する

Last updated at Posted at 2020-04-21

Windows Terminal (Preview)を使うと、PowerShellやWSLを1ターミナル内でタブ分けできる。

設定を変えたい場合、タブの一番右にある ボタンから Settingsをクリックすると profiles.jsonが開かれる。
image.png

自力で書くのか… :innocent:

Windows Terminalの公式ドキュメントに色々書いてある。

cf. https://github.com/microsoft/terminal/blob/master/doc/user-docs/index.md

Schemaを編集するための公式ドキュメントを見つつ、追加する。
cf. https://github.com/microsoft/terminal/blob/master/doc/cascadia/SettingsSchema.md

色やフォントを変える

たとえば全体的に背景色・前景色・フォント・フォントサイズを決めておきたかったので、こうした。

profiles.json(抜粋)
  ...
  "profiles":
      {
          "defaults":
          {
              // Put settings here that you want to apply to all profiles
+             "background": "#000000",
+             "foreground": "#55dd55",
+             "fontFace": "源ノ角ゴシック",
+             "fontSize": 14
          },
          "list":
          ...

画面サイズ

起動時の画面サイズを最初から広くしておきたいので、こうした。

profiles.json(抜粋)
  ...
  {
      "$schema": "https://aka.ms/terminal-profiles-schema",
      "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
+     "initialCols": 205,
+     "initialRows": 40,
      "profiles":
      ...

画面の位置

起動時の画面が変な位置 (中央?)に固定されていたので、左端の下側に固定するよう変えた。

profiles.json(抜粋)
  ...
  {
      "$schema": "https://aka.ms/terminal-profiles-schema",
      "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
      "initialCols": 205,
      "initialRows": 40,
+     "initialPosition": "0,200",
      "profiles":
      ...

起動時に開く端末を変える

デフォルトではPowerShellとかが開く。

WSL2のUbuntuに変えたければ、 "defaultProfile"の値を、同設定ファイル内にあるUbuntuの guidで上書きする。

WSL2起動時のディレクトリ位置を指定

startingDirectoryで指定できる。

たとえば /home/v2okimochiがホームディレクトリでそこを指定したければこうする

profiles.json(抜粋)
  ...
  {
      "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
      "hidden": false,
      "name": "Ubuntu-18.04",
      "source": "Windows.Terminal.Wsl",
+     "startingDirectory": "//wsl$/Ubuntu-18.04/home/v2okimochi" 
  },
  ...

WSL2起動時に.bashrcを読み込む

読み込まれない疑惑があったので。

commandlineで、bashを起動するように指定する

profiles.json(抜粋)
  ...
  {
      "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
      "hidden": false,
      "name": "Ubuntu-18.04",
      "source": "Windows.Terminal.Wsl",
+     "commandline" : "wsl -d Ubuntu-18.04 bash"
  },
  ...

cf. WindowsTerminalやPowerShellからWSL2を実行した際に~/.bashrcが読み込まれない

発展

さらに詳しい解説 (キーバインドなど)もあった。

cf. Windows Terminal (Preview) メモ

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3