Powerlevel10k: Pre command hook does not work with p10k

Created on 20 Jan 2020  Â·  4Comments  Â·  Source: romkatv/powerlevel10k

Hello. I'm using p10k with zplugin as recommended:
https://github.com/alex-popov-tech/.dotfiles/blob/master/terminal/zshell/zsh_plugins#L8
as well with another plugin:
https://github.com/alex-popov-tech/.dotfiles/blob/master/terminal/zshell/zsh_plugins#L20
But the hardcore option do not work in the current setup:

   ~ I git status
Found existing alias for "git status". You should use: "gst"
fatal: not a git repository (or any of the parent directories): .git
   ~ I export YSU_HARDCORE=1                       
   ~ I git status           
Found existing alias for "git status". You should use: "gst"
You Should Use hardcore mode enabled. Use your aliases!
fatal: not a git repository (or any of the parent directories): .git    <<<< that line should not be printed

however, if i will commend p10k plugin it works as expected:

start typing...git status       
Found existing alias for "git status". You should use: "gst"
fatal: not a git repository (or any of the parent directories): .git
start typing...export YSU_HARDCORE=1      
start typing...git status        
Found existing alias for "git status". You should use: "gst"
You Should Use hardcore mode enabled. Use your aliases!

Any ideas about what could go wrong here? I tried multiple plugins like this one, and with all of them had the same issue.

Most helpful comment

The only my question is - I tried to compare instant prompt on/off and had the same results (~0.13s) using for i in $(seq 1 10); do /usr/bin/time /bin/zsh -i -c exit; done;. Is my prompt loading so quick so I can't see the profit of instant_prompt improvement?

This benchmark isn't measuring anything useful. For example, try using zsh with the following ~/.zshrc:

precmd() sleep 1

You'll notice that it takes one second for prompt to appear. However, time zsh -ic '' reports only a few milliseconds. What you, as a user of zsh, care about is how long it takes before you see prompt, before you can start typing, and so on for all the useful detectable things.time zsh -ic '' measures how long it takes to source some of the zsh initialization files, which isn't all that useful.

If you apply my patch, you'll notice that starting zsh instantly gives you p10k prompt and lets you start typing right away.

If you run POWERLEVEL9K_INSTANT_PROMPT=off zsh, you should notice delay between starting zsh and prompt appearing.

Instant prompt in p10k has several advantages over deferred loading provided by zplugin.

  1. You can load your plugins any way you like. You are not tied to zplugin for performance reasons anymore.
  2. You get your proper prompt right away. No more "start typing...".
  3. You no longer rely on implementation details of plugins. No need to call their internal functions. No need to expose yourself to weird initialization bugs caused by initialization from zle.

In the rare case where you do need deferred initialization, https://github.com/romkatv/zsh-defer can be helpful. It's much easier to use than zplugin, works better and doesn't tie you to any plugin manager. You simply prepend zsh-defer in front of every command that you want deferred. You can even use zsh-defer zplugin light some/plugin to get a better version zplugin ice wait. I should repeat that it's unlikely that you'll need to defer anything once you enable instant prompt.

All 4 comments

Hello. I'm using p10k with zplugin as recommended

The way you are loading p10k is unsupported. It may break at any time, or it could already be broken. See documentation: https://github.com/romkatv/powerlevel10k/blob/master/README.md#zplugin.

I know that zplugin "wiki" lists unsupported/invalid/broken uses of p10k. Despite its name, that's not a wiki, so I cannot edit it. There is an officially supported way for every broken p10k recipe from the zplugin wiki. E.g., for loading, see above.

You can make zsh start faster and smoother with a change like this: https://github.com/alex-popov-tech/.dotfiles/compare/master...romkatv:faster-zsh-startup. It enables instant prompt in p10k and disables deferred loading (wait ice) of zplugin.

But the hardcore option do not work in the current setup

Thanks for the bug report! Fixed. Please update and try again.

Hello @romkatv ! Thanks a lot for the fast response, I've updated p10k, and now it's working as expected.

The only my question is - I tried to compare instant prompt on/off and had the same results (~0.13s) using for i in $(seq 1 10); do /usr/bin/time /bin/zsh -i -c exit; done;. Is my prompt loading so quick so I can't see the profit of instant_prompt improvement?

The only my question is - I tried to compare instant prompt on/off and had the same results (~0.13s) using for i in $(seq 1 10); do /usr/bin/time /bin/zsh -i -c exit; done;. Is my prompt loading so quick so I can't see the profit of instant_prompt improvement?

This benchmark isn't measuring anything useful. For example, try using zsh with the following ~/.zshrc:

precmd() sleep 1

You'll notice that it takes one second for prompt to appear. However, time zsh -ic '' reports only a few milliseconds. What you, as a user of zsh, care about is how long it takes before you see prompt, before you can start typing, and so on for all the useful detectable things.time zsh -ic '' measures how long it takes to source some of the zsh initialization files, which isn't all that useful.

If you apply my patch, you'll notice that starting zsh instantly gives you p10k prompt and lets you start typing right away.

If you run POWERLEVEL9K_INSTANT_PROMPT=off zsh, you should notice delay between starting zsh and prompt appearing.

Instant prompt in p10k has several advantages over deferred loading provided by zplugin.

  1. You can load your plugins any way you like. You are not tied to zplugin for performance reasons anymore.
  2. You get your proper prompt right away. No more "start typing...".
  3. You no longer rely on implementation details of plugins. No need to call their internal functions. No need to expose yourself to weird initialization bugs caused by initialization from zle.

In the rare case where you do need deferred initialization, https://github.com/romkatv/zsh-defer can be helpful. It's much easier to use than zplugin, works better and doesn't tie you to any plugin manager. You simply prepend zsh-defer in front of every command that you want deferred. You can even use zsh-defer zplugin light some/plugin to get a better version zplugin ice wait. I should repeat that it's unlikely that you'll need to defer anything once you enable instant prompt.

Okay, that explains! Thanks a lot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

barthalion picture barthalion  Â·  3Comments

rpathak38 picture rpathak38  Â·  4Comments

romkatv picture romkatv  Â·  5Comments

sanathkumarbs picture sanathkumarbs  Â·  3Comments

Mystic8b picture Mystic8b  Â·  4Comments