0
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?

🔰はじめてのzsh初期化エラー

Last updated at Posted at 2025-03-31

ええ、私はじめて出会いました。

[WARNING]: Console output during zsh initialization detected.

When using Powerlevel10k with instant prompt, console output during zsh
initialization may indicate issues.

You can:

  - Recommended: Change ~/.zshrc so that it does not perform console I/O
    after the instant prompt preamble. See the link below for details.

    * You will not see this error message again.
    * Zsh will start quickly and prompt will update smoothly.

  - Suppress this warning either by running p10k configure or by manually
    defining the following parameter:

      typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet

    * You will not see this error message again.
    * Zsh will start quickly but prompt will jump down after initialization.

  - Disable instant prompt either by running p10k configure or by manually
    defining the following parameter:

      typeset -g POWERLEVEL9K_INSTANT_PROMPT=off

    * You will not see this error message again.
    * Zsh will start slowly.

  - Do nothing.

    * You will see this error message every time you start zsh.
    * Zsh will start quickly but prompt will jump down after initialization.

For details, see:
https://github.com/romkatv/powerlevel10k#instant-prompt

-- console output produced during zsh initialization follows --

/Users/xxxxxx/.zshrc:131: command not found: pyenv

何が起きてるのか

Powerlevel10kのインスタントプロンプト機能を使用している際に、zshの初期化中にコンソール出力が検出されたとのこと。
zshの初期化中に何らかのコマンドが実行され、その結果がコンソールに表示されることが原因らしいです。

インスタントプロンプト機能ってなに?

🤖Powerlevel10kのインスタントプロンプト機能は、zshシェルの起動速度を大幅に向上させるための機能です。

インスタントプロンプトの設定を見てみよう

こんなやつ
環境構築したときにコピペで貼ったやつ

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

zshの初期化ってのは、ターミナルのウィンドウを閉じて開く度に実行される?

🤖ターミナルを開くと~/.zshrcファイルが読み込まれ、そこに記述された設定やコマンドが実行されます。
この初期化プロセスには、環境変数の設定、エイリアスの定義、プラグインの読み込みなどが含まれます。

具体的にコンソール出力が実行されたログとかはどっかで見れる?

試してないけど、方法はあるとのこと。

🤖いくつかの方法があります。
1. ~/.zshrc ファイルの確認
~/.zshrc ファイルを開いて、どのコマンドが実行されているか確認します。特に、pyenv に関連する行がエラーを引き起こしている可能性があります。

2. script コマンドを使用してログを記録する
script コマンドを使用して、ターミナルのセッションを記録することができます。以下のように設定することで、zshの初期化中に実行されたコマンドを含むすべての出力をログファイルに保存できます

script -a ~/zsh_init_log.txt
zsh
exit

このコマンドを実行すると、~/zsh_init_log.txt にすべての出力が記録されます。

3. set -x を使用してデバッグモードにする
~/.zshrc の先頭に set -x を追加すると、実行されるすべてのコマンドがコンソールに表示されます。これにより、どのコマンドが出力を行っているかを特定できます2:

set -x
# ここに他の設定やコマンドを記述
set +x

対処法

警告文には4つの方法が記載されています。
1. 推奨
~/.zshrcを変更し、インスタントプロンプトの前にコンソールI/Oを行わないようにする。エラーメッセージが表示されなくなるし、zshも爆速で起動するし、プロンプトがスムーズに更新されてみんなハッピー。

2. 警告を抑制する
p10k configure を実行するか、以下パラメータを手動で定義する

typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet

エラーメッセージが表示されなくなって、zshが爆速で起動するけど、初期化後にプロンプトが下に移動する。

3. インスタントプロンプトを無効にする
p10k configure を実行するか、以下パラメータを手動で定義する

typeset -g POWERLEVEL9K_INSTANT_PROMPT=off

エラーメッセージが表示されなくなるけど、zshの起動は遅くなる。

4. 放置
毎回この警告文が表示される。

やったこと

推奨の方法でメッセージなくなりました!
pyenv関連の設定がコンソール出力を行っていたようで、これらをインスタントプロンプトの設定よりも前に持っていくことで解決

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$HOME/Library/Python/3.9/bin:$PATH"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

最後に

解決したけど、なんでこれが突然出力されるようになったかわからん。
何もしてないのに

0
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
0
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?