ターミナルプロンプトをカスタマイズしていろいろな情報を表示できるようにする oh-my-posh を紹介します。 プロンプトに処理結果や処理時間、Gitステータスなどを表示できるようになります。


どのような見た目になるか

Oh My Posh を使うとどのようになるのかイメージがわかないかもしれないので先に使用例を挙げます。 確認環境は WSL上のUbuntuおよび素のUbuntuです。バージョンは下記の通り。

1
2
3
4
5
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.2 LTS"

下記の例ではOS名、コマンドの処理時間、処理結果が表示されています。いちいち timeecho $?しなくていいので便利です。

Oh My Poshでコマンド処理時間と実行結果をプロンプトに表示

さらにGitHubのディレクトリではこんな感じです。GitHubアイコンとブランチ名、ステータスがわかるようになります。

Gitリポジトリのブランチ名とステータスをアイコン表示

Python仮想環境だとバージョンが表示されたりもします。

Python仮想環境でバージョンとアイコンを表示

このようにプロンプトを便利な表現にできます。

導入方法

インストール

まずはインストールします。公式ドキュメントにインストール方法の記載あります。特に難しいことはないです。 公式サイトにある Set up your terminal の手順に沿って実行すればよいです。 Linuxなら下記のとおりです(2025-06-22現在)。

1
2
3
$ curl -s https://ohmyposh.dev/install.sh | bash -s
$ which oh-my-posh
/home/shinya/bin/oh-my-posh

NERD FONTS のダウンロード

最初の例でも示したようにGitHubやPythonのアイコンも表示可能ですのでそれらに対応したフォントが必要です。 ここでは開発者向けにアイコンを追加したフォント群のNerds Fonts を利用します。 お好みで選べばOKですが、今回の例では日本語もいい感じに表示してくれるBizin Gothicを使用しています。 どのようなフォントかは窓の杜の 日本人プログラマー向けコーディングフォント「Bizin Gothic」が無償公開 などを参照ください。

フォントのインストールはお使いのOSに合わせてやってください。通常と変わらない方法でOKです。よくわからなければググれば出てきます。 ちなみにWSLでのフォントの指定は下記のようにできます。今回は Bizin Gothic Discord NFを使用しています。NFは NERD FONTSの略です。

WSLのターミナル設定でNerd Fontを指定する例

テーマのダウンロード

公式サイトにたくさんのテーマが置いてあります。下記の手順でダウンロードします。

1
2
3
4
5
mkdir ~/.poshthemes
wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip
unzip ~/.poshthemes/themes.zip -d ~/.poshthemes
chmod u+rw ~/.poshthemes/*.omp.*
rm ~/.poshthemes/themes.zip

テーマの反映

下記のコマンドにてテーマのjsonファイルを指定すれば反映されます。 ~/.poshthemes/ 以下にたくさんテーマがあるのでお好みのものを指定すればOKです。

1
eval "$(oh-my-posh init bash --config ~/.poshthemes/hoge.json)"

参考に、試しにいくつか設定してみた例を示します。コマンド実行すると即時で反映されてプロンプトが変化します。いろいろなjsonファイルで試してお気に入りを見つけてみてください。

複数のOh My Poshテーマを適用したプロンプト表示例

また、公式サイトのThemesにもたくさん表示例があるのでそちらも参考になると思います。

カスタマイズ方法

既存のテーマで飽き足らない場合は自分でカスタマイズすることも可能です。 公式サイトのConfigurationの説明に沿ってjsonファイルを修正すればよいです。 結構大変かもしれませんが凝りたい人はやってみてください。

Nerd Fontsのユニコードの確認

テーマのjsonファイル内で、NERD FONTSのアイコンはユニコードで指定されています。 例えばPythonのアイコンは \ue235となっています。 このユニコードだけみてもどんなアイコンかわからないのでNerd Fonts Cheat Sheet のチートシートを使うと便利です。 たとえば \ue235 を入力すると下記のようにPythonのアイコンが表示されます(ユニコードエスケープシーケンス\u は省いてください)。

Nerd Fonts Cheat Sheetでアイコンを検索する画面

その他は公式サイト見ながらカットアンドトライやればできると思います。頑張ってください。

テーマのサンプル

参考までに手元でカットアンドトライしてみたテーマのjsonを貼っておきます。冒頭にて紹介した表示例になります。 もとのテーマファイルがzsh向けだったのをbashむけにちょこちょこ修正したものです、細かいところはまちがっているかもなのであくまで参考までです。

テーマのサンプル
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "left",
      "segments": [
        {
          "background": "#d3d7cf",
          "foreground": "#000000",
          "leading_diamond": "\ue0b2",
          "style": "diamond",
          "template": " {{ if .WSL }}WSL{{ end }}{{.Icon}} ",
          "type": "os"
        },
        {
          "background": "#91ddff",
          "foreground": "#100e23",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "home_icon": "~",
            "style": "full"
          },
          "style": "powerline",
          "template": " \uf07c {{ .Path }} ",
          "type": "path"
        },
        {
          "background": "#4e9a06",
          "background_templates": [
            "{{ if or (.Working.Changed) (.Staging.Changed) }}#ff9966{{ end }}",
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#f26d50{{ end }}",
            "{{ if gt .Ahead 0 }}#89d1dc{{ end }}",
            "{{ if gt .Behind 0 }}#4e9a06{{ end }}"
          ],
          "foreground": "#000000",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "branch_icon": "\uf126 ",
            "fetch_stash_count": true,
            "fetch_status": true,
            "fetch_upstream_icon": true
          },
          "style": "powerline",
          "template": " {{ .UpstreamIcon }} {{ .HEAD }} {{if .BranchStatus }}{{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ",
          "type": "git"
        },
        {
          "background": "#689f63",
          "foreground": "#ffffff",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "fetch_version": true
          },
          "style": "powerline",
          "template": " {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} \ue718 ",
          "type": "node"
        },
        {
          "background": "#00acd7",
          "foreground": "#111111",
          "invert_powerline": true,
          "powerline_symbol": "\ue0b0",
          "properties": {
            "fetch_version": true
          },
          "style": "powerline",
          "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue627 ",
          "type": "go"
        },
        {
          "background": "#4063D8",
          "foreground": "#111111",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "fetch_version": true
          },
          "style": "powerline",
          "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue624 ",
          "type": "julia"
        },
        {
          "background": "#FFDE57",
          "foreground": "#111111",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "display_mode": "files",
            "fetch_virtual_env": false
          },
          "style": "powerline",
          "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue235 ",
          "type": "python"
        },
        {
          "background": "#AE1401",
          "foreground": "#ffffff",
          "invert_powerline": true,
          "powerline_symbol": "\ue0b2",
          "properties": {
            "display_mode": "files",
            "fetch_version": true
          },
          "style": "powerline",
          "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue791 ",
          "type": "ruby"
        },
        {
          "background": "#FEAC19",
          "foreground": "#ffffff",
          "invert_powerline": true,
          "powerline_symbol": "\ue0b2",
          "properties": {
            "display_mode": "files",
            "fetch_version": false
          },
          "style": "powerline",
          "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \uf0e7",
          "type": "azfunc"
        },
        {
          "background_templates": [
            "{{if contains \"default\" .Profile}}#FFA400{{end}}",
            "{{if contains \"jan\" .Profile}}#f1184c{{end}}"
          ],
          "foreground": "#ffffff",
          "invert_powerline": true,
          "powerline_symbol": "\ue0b2",
          "properties": {
            "display_default": false
          },
          "style": "powerline",
          "template": " {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} \ue7ad ",
          "type": "aws"
        },
        {
          "background": "#ffff66",
          "foreground": "#111111",
          "invert_powerline": true,
          "powerline_symbol": "\ue0b2",
          "style": "powerline",
          "template": " \uf0ad ",
          "type": "root"
        },
        {
          "background": "#a9a9a9",
          "foreground": "#000000",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "always_enabled": true
          },

          "style": "powerline",
                        "template": " {{ .FormattedMs }}",
          "trailing_diamond": "\ue0b0",
          "type": "executiontime"
        },
        {
          "background": "#007ACC",
          "background_templates": [
            "{{ if gt .Code 0 }}#cc2222{{ end }}"
          ],
          "foreground": "#d3d7cf",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "always_enabled": true
          },
          "style": "powerline",
          "template": " {{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }} ",
          "type": "status"
        }
      ],
      "type": "prompt"
    }
  ],
  "console_title_template": "{{ .Shell }} in {{ .Folder }}",
  "final_space": true,
  "version": 3
}

まとめ

今回はプロンプトをかっこよくする Oh My Posh を紹介しました。 プロンプトをビジュアライズして実行時間や実行結果、Gitのステータスなどをわかりやすく表示できます。カスタマイズ性もあるのでご自分の好みに合わせてかっこよくしてみてください!