Skip to content

GhosttyからリモートのLinuxへSSHした際、プロンプトの色などが正しく表示されない問題を解決する

Ghosttyで開始したシェルから別のLinuxサーバへSSHしたところ、プロンプトの色が正しく表示されませんでした。Terminfoには以下の記載がありました。

Ghostty's terminfo entry is available in ncurses 6.5-20241228 and above. As distros update their ncurses packages, Ghostty's terminfo entry will be available by default system-wide. This will take time to propagate.

確かに、デフォルト状態のGhosttyはTERM環境変数として(xterm-256colorなどではなく)xterm-ghosttyという文字列を送信していました。これを回避する手段として同ページに以下の記載がありました。

Both variants can be automated by specifying one or both of the following in your Ghostty configuration:

  1. shell-integration-features = ssh-terminfo to copy the terminfo entry the first time you log into a new server over SSH.
  2. shell-integration-features = ssh-env to configure SSH to fall back to xterm-256color.

回避策1

この記載に従って.config/ghostty/configを以下のように変更しました。

変更前
shell-integration-features = cursor,no-sudo,title,no-ssh-env,no-ssh-terminfo,path
変更後
shell-integration-features = cursor,no-sudo,title,ssh-env,ssh-terminfo,path

これでリモートのLinuxへSSHログインしても意図した色が表示されるようになりました。ncurses 6.5-20241228以降が広く普及すれば自然とこの問題は解決すると思われますが、当面はこの方法で回避可能なようです。

回避策2

もしくは~/.config/ghostty/configに以下のようにtermオプションを追加することでも回避可能です。

変更前
term = xterm-ghostty
変更後
term = xterm-256color