powerlevel10k: `reset-prompt` doesn't show changed directory
How to reproduce it: 1.
docker run -e LANG=C.UTF-8 -e LC_ALL=C.UTF-8 -e TERM=$TERM -it --rm ubuntu bash -uexc '
cd
apt update && apt install -y zsh git vim
git clone https://github.com/romkatv/powerlevel10k.git
echo "
cd_pp() {
cd ..
zle .reset-prompt && zle -R
}
zle -N cd_pp
bindkey '\''^[[1;5A'\'' cd_pp
source ~/powerlevel10k/powerlevel10k.zsh-theme" >~/.zshrc
exec zsh'
- press
<ctrl-up> - press
<enter>or typepwd

About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 94 (90 by maintainers)
Not sure if this is helpful but I just discovered:
For redrawing the prompt without executing the line and maintaining the contents of the line and not setting the error code to 1 đ
This is now fixed. Hereâs a summary of the ZSH bug.
Bug introduced in https://github.com/zsh-users/zsh/commit/d8d9fee137a5aa2cf9bf8314b06895bfc2a05518.
ZSH_PATCHLEVEL=zsh-5.4.2-159-gd8d9fee13. Released in 5.5.Bug fixed in https://github.com/zsh-users/zsh/commit/64d13738357c9b9c212adbe17f271716abbcf6ea.
ZSH_PATCHLEVEL=zsh-5.7.1-50-g64d137383. Not released yet.Test (fails on buggy ZSH, passes on correct ZSH):
Workaround (passes on buggy ZSH, fails on correct ZSH):
Unfortunately, the workaround cannot be applied unconditionally. Doing so would break p10k on ZSH without the bug. So now there is a branch in p10k to apply the workaround if and only if ZSH has the bug. Code: https://github.com/romkatv/powerlevel10k/blob/8b8743c8edc548981274184cfc922757e99df0ea/powerlevel9k.zsh-theme#L2331
I also enabled the display of the number of staged and unstaged changes in git prompt in Pure Power. Itâs a new feature I implemented last week when a user asked for it. I havenât used it myself yet. Not sure itâs worth the real estate. You might like it as you generally prefer more bells and whistles in the prompt.
These are controlled by
POWERLEVEL9K_VCS_MAX_NUM_{STAGED,UNSTAGED,UNTRACKED}. In Pure Power I set them like this:Itâll show all staged and unstaged but only an icon for untracked. Make sure to not set
POWERLEVEL9K_VCS_MAX_NUM_UNTRACKED=-1as itâll cause massive performance issues in some cases. If you want to see the number of untracked files, usePOWERLEVEL9K_VCS_MAX_NUM_UNTRACKED=99.With
ZSH_AUTOSUGGEST_MANUAL_REBIND=1zsh-autosuggestions behaves like a regular plugin â it wraps all zle widgets only once during initialization.With
ZSH_AUTOSUGGEST_MANUAL_REBIND=0it wraps them during initialization but also on everyprecmd. This allows you to define new zle widgets in an interactive prompt (rather than in~/.zshrc) and have them instantly be recognized by zsh-autosuggestions. Needless to say, no one does that, and no one expects changes made to zle widgets in an interactive prompt to propagate into plugins without restarting zsh or at least re-sourcing~/.zshrc.This extravagance costs a lot though.Itâs almost certain that there would not even be an option like
ZSH_AUTOSUGGEST_MANUAL_REBIND=0right now if the default behavior of zsh-autosuggestions wasZSH_AUTOSUGGEST_MANUAL_REBIND=1to begin with. Case in point is zsh-syntax-highlighting. It also needs to wrap all zle widgets to work correctly but doesnât have the option to do it on every precmd. So even if you donât setZSH_AUTOSUGGEST_MANUAL_REBIND=1, you still cannot define widgets in an interactive session, because no plugins other than zsh-autosuggestions will pick them up.tl;dr: Set
ZSH_AUTOSUGGEST_MANUAL_REBIND=1. The only difference youâll notice is faster prompt.âď¸
This is an internal function. You technically can call internal functions but if you do, you are on your own.
By refreshing the prompt I meant calling
zle accept-line. This will do everything thatâs necessary to refresh prompt and will work with any theme.Thanks for the high-quality bug report. The docker command is especially appreciated.
In this formulation Iâm tempted to say this is not an issue. Powerlevel10k indeed doesnât reevaluate the whole prompt on
reset-prompt. Itâs not just dir prompt, either. If you addgit somethingincd_pp, git prompt wonât be updated. Same thing forpyenv local systemand pyenv prompt. In fact, every theme that installs aprecmdcan be âbrokenâ in this way by changing external environment from a zle widget.The fact that Powerlevel10k doesnât reevaluate some parts of the prompt is a feature. This enables things like responsive
vi_modethat would be be impossible to provide ifreset-promptreevaluated the whole prompt.Does the example you gave represent a real problem you are trying to solve? If so, there are solutions. The simple solution is this:
The downside is that itâll clear your buffer, so you cannot type a command, press
<ctrl-up>and then execute the command in the new directory. This can be solved with some extra code. In my dotfiles I bind<alt-left>to go to the previous directory,<alt-right>to go to the next,<alt-up>tocd ..(the same as you have on<ctrl-up>) and<alt-down>to print directory history (to know where<alt-left>and<alt-right>will go). None of these clear the buffer. The code isnât complex but I have it in a rather messy state, so it can be difficult to read.Hereâs a demo: https://asciinema.org/a/CKhNEndylHW7uOxFmWcKoESfQ.
I first populate directory history by executing
cda bunch of times. Then I show this history withdirs -vand again by pressing<alt-down>. Then I typepand press<alt-left>(go back in history) and<alt-right>(go forward in history) and finish with another<alt-down>.I forgot to mention that
<alt-left>,<alt-right>and<alt-up>print directory history but itâs truncated at 3 entires.<alt-down>prints longer history (truncated at 20).Notice that it plays nice with
zsh-autosuggestionsandzsh-syntax-highlighting. The color ofpin the prompt changes depending on whether the current directory has a subdirectory whose name starts withpor not, so it has the same color as if I typedpin that directory.If these workarounds are good enough for you, I suggest to close the issue. If not, please describe what you are trying to achieve.