1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL2 + zsh + oh-my-zsh が重い人へ

WSL2 で zsh + oh-my-zsh を使ってたら以下の症状がでた。

  • ターミナル起動がワンテンポ遅い
  • Git 管理下のディレクトリで入力がもたつく
  • 「別にそんなにプラグイン使ってないのに重い…」
  • 見た目は好きだけど、速度は犠牲にしたくない

そこでいろいろ探したところ、、、
oh-my-zsh をやめて Starship にしたら全部解決しました。

この記事では、

  • なぜ oh-my-zsh が重く感じるのか
  • Starship とは何者なのか
  • WSL2 環境での安全な移行手順

までまとめます。


この記事が対象とする人

  • WSL2 ユーザー
  • oh-my-zsh が重いと感じている人
  • devcontainer 風見た目が好きな人
  • シェル設定を「シンプルに保ちたい」人

なぜ oh-my-zsh は重く感じるのか

oh-my-zsh はとても便利ですが、WSL2 では特に次が効いてくる。

  • 起動時に大量の shell script を読み込む
  • Git 情報を 同期的に取得するテーマが多い
  • プラグインが増えるほど指数的に遅くなる
  • WSL2 のファイル I/O が Linux ネイティブより遅い

つまり、

「WSL2 × oh-my-zsh × Git」 = 体感遅延が出やすい
という構図。


Starship とは?

Starship は Rust 製の超高速プロンプトエンジン
特徴:

  • とにかく速い
  • zsh / bash / fish 共通
  • 設定は starship.toml 1ファイル
  • Git 情報は最適化・非同期
  • 見た目を自由にカスタマイズ可能

「プロンプトだけ」を担当する
シェル本体を汚さないのが最大の利点。


移行方針

今回の移行はこの考え方で行った。

  • oh-my-zsh は 完全アンインストール
  • zsh は 素の状態に戻す
  • プロンプトだけ Starship に任せる
  • 何かあっても 即元に戻せる

oh-my-zsh のアンインストール

uninstall_oh_my_zsh

これで:

  • ~/.oh-my-zsh は削除
  • .zshrc はバックアップ付きで復元
    ログインシェルが bash に戻るので、zsh に戻した。
chsh -s /usr/bin/zsh
exec zsh

Starship のインストール

curl -sS https://starship.rs/install.sh | sh

確認:

starship --version

最小・高速な .zshrc

WSL2 では これくらいが正解だった。

# ========================
# Locale (English output)
# ========================
export LANG=en_US.UTF-8
unset LC_ALL
# ========================
# Editor
# ========================
export EDITOR=vim
# ========================
# History
# ========================
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt hist_ignore_dups
setopt share_history
# ========================
# Completion (fast)
# ========================
autoload -Uz compinit
compinit -C
# ========================
# Starship
# ========================
command -v starship >/dev/null 2>&1 && eval "$(starship init zsh)"

ポイント:

  • LC_ALL使わない
  • locale は en_US.UTF-8(日本語入力は問題なし)
  • プロンプト以外は極力触らない

自分用devcontainers 風 Starsh

~/.config/starship.toml

add_newline = false
format = """
[${custom.vscode_user} ](green)${character}[${directory} ](bold blue)${git_branch}${git_status}[\\$ ](white)
"""
[custom.vscode_user]
command = "echo vscode"
when = "true"
style = "green"
[character]
success_symbol = "[➜ ](reset)"
error_symbol = "[➜ ](bold red)"
[directory]
truncation_length = 4
style = "bold blue"
[git_branch]
format = "[\\(](bold cyan)[$branch](bold red)"
[git_status]
format = "[$modified]($style)[\\)](bold cyan) "
style = "bold yellow"
modified = " ✗"
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?