Open M4he opened 3 years ago
Thanks for this great report! As we've previously discussed on IRC, this is a valid bug report even the reporter is using some very old qterminal as I'm able to reproduce the issue on Arch Linux with the latest git-master.
on Ubuntu it only occasionally happens without oh-my-zsh
That is a useful information. I moved away from oh-my-zsh some time ago. It might be the reason that I seldom see such an issue recently.
@M4he
Go inside the .zshrc file at the top you'll find:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
<- uncomment this line
That's what worked for me
@xZliman
I tried adding your quoted line¹ (uncommented) to the very top of my ~/.zhsrc
file but it doesn't make a difference for me.
¹ I did not have the comment in mine, because my file was based on an older template apparently.
@M4he
I also encountered this problem, I use oh-my-zsh and powerlevel10k, I found that powerlevel10k instant prompt feature caused this problem:
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
Adding this statement at the top of the .zshrc prints a reflected % on the first line of the newly opened terminal, like this:
I tracked the start-up of the zsh, but in the end I didn't find the cause of the problem, but it must have been caused by powerlevel10k's instant prompt, my simple solution is to discard all the output:
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" > /dev/null fi
This really solved my problem.
I hope this will help you.
@M4he I also encountered this problem, I use oh-my-zsh and powerlevel10k, I found that powerlevel10k instant prompt feature caused this problem:
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
Adding this statement at the top of the .zshrc prints a reflected % on the first line of the newly opened terminal, like this: I tracked the start-up of the zsh, but in the end I didn't find the cause of the problem, but it must have been caused by powerlevel10k's instant prompt, my simple solution is to discard all the output:if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" > /dev/null fi
This really solved my problem. I hope this will help you.
This worked great for me and I tried all other solutions! This was the only solution that provided results.
@M4he I also encountered this problem, I use oh-my-zsh and powerlevel10k, I found that powerlevel10k instant prompt feature caused this problem:
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
Adding this statement at the top of the .zshrc prints a reflected % on the first line of the newly opened terminal, like this: I tracked the start-up of the zsh, but in the end I didn't find the cause of the problem, but it must have been caused by powerlevel10k's instant prompt, my simple solution is to discard all the output:if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" > /dev/null fi
This really solved my problem. I hope this will help you.
I can reproduce this solution.
Thanks!
Hey everyone. I'm the developer of powerlevel10k. @flaviocamilo has tagged me on https://github.com/romkatv/powerlevel10k/issues/1445.
When you see the inverted percent before the first prompt upon opening a new terminal, this is almost always caused by a bug in the terminal or the window manager (wm). You can diagnose the nature of the bug with the following steps.
First, add this snippet at the very top of ~/.zshrc
:
PS1='%~ '
RPS1='%n@%m'
return
This sets left and right prompt to very simple values and returns before evaluating anything else in your zsh config. If you can reproduce the problem with this .zshrc
(that is, you still occasionally get the inverted percent sign upon opening a new terminal), this means the issue is not with your zsh theme or your zsh config in general.
The next step is to figure out which of the two common terminal/wm bugs is the culprit. The most common variety is that the TTY reports its size incorrectly for a short while after being created. To see whether this is the case add the following snippet at the very top of ~/.zshrc
:
print -r -- "$COLUMNS x $LINES"
sleep 1
print -r -- "$COLUMNS x $LINES"
When you open a new terminal, you should see the same dimensions printed twice and they should match the real dimensions of your terminal window. If you see different numbers reported on the first and the second line, or if they don't match the real dimensions of the terminal window, this is an indication of the bug I was referring to earlier.
If you always see correct dimensions printed twice, check for another terminal/wm bug that can cause the inverted percent sign. This bug involves incorrect line wrapping during a short duration after the TTY is created. To check for it, add the following snippet at the very top of ~/.zshrc
:
() {
emulate -L zsh -o prompt_percent
local -i n='COLUMNS - 1'
print -Prn -- X${(pl.$n.. .)}$'\r%E'
}
When you open a new terminal, you should NOT see "X" at the top of your terminal window. If you do see it, that's a bug in the terminal/wm.
Now, why do you see the inverted percent sign when using powerlevel10k instant prompt but not when using other themes? This is simply because other themes are unable to display prompt fast enough. Powerlevel10k displays prompt very quickly after you open a terminal window, so it can be affected by a terminal/wm bug that only manifests itself for a short duration after a TTY is created.
my simple solution is to discard all the output:
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" > /dev/null fi
By redirecting the output to /dev/null
you've disabled instant prompt. If you really want to disable instant prompt, simply delete this whole snippet. It'll have the same effect (no instant prompt) and will be simpler and faster. Alternatively, you can leave the original instant prompt snippet unchanged and set POWERLEVEL9K_INSTANT_PROMPT=off
in ~/.p10k.zsh
(search that file for "POWERLEVEL9K_INSTANT_PROMPT" -- this parameter is already present there but with a different value). You can also do this by running p10k configure
and selecting "Off" when asked what you want w.r.t. instant prompt.
These are just workarounds though. Ideally the bug needs to be fixed in the terminal or the window manager.
sleep x
reduces the frequency of %
occurrence while retaining instant prompt, add sleep 0.1
at the top of ~/.zshrc
. Sleep time can be tried by yourself. For me, if the sleep time is between 0.05 and 0.1, about 15 zsh starts will have 1 %
. The benefit is that the shell starts faster than simply disable instant prompt.
@gitzhangzhao Could you try it with the latest version of Powerlevel10k? I’ve implemented a partial workaround that might get rid of the inverted percent sign even without the sleep
.
@gitzhangzhao Could you try it with the latest version of Powerlevel10k? I’ve implemented a partial workaround that might get rid of the inverted percent sign even without the
sleep
.
@romkatv It worked, thank you very much!
@gitzhangzhao Thanks for verifying!
It's really just a workaround though. As I mentioned earlier, this is a bug either in the terminal or in the window manager. The bug is not specific to powerlevel10k and can easily be reproduced with a tiny zsh config. It's not specific to zsh either, which can be demonstrated by instructing the terminal to launch stty size
instead of the login shell. You should see that the output of stty size
doesn't match the real terminal dimensions when you open a new terminal.
Expected Behavior
konsole
,gnome-terminal
,tilix
etc.)zsh
and oh-my-zsh configurations properlyCurrent Behavior
zsh
set as the default shell, a color-inverted percent sign (%
) will displayed above the promptzsh
andprompt adam1
set in~/.zshrc
zsh
as default shell and oh-my-zsh set upPossible Solution
I have found the following two end-user workarounds (not solutions) so far. Both with downsides. The permanent solution would be to fix whatever is causing this in qterminal directly.
Workaround 1
~/.zshrc
:Workaround 2
~/.zshrc
:%
disappear but an empty line will still be displayed above prompts in new qterminal instancesSteps to Reproduce (for bugs)
*-xfce.iso
from here). All following instructions refer to the live system..zshrc
in the current home directory (~/.zshrc
) with the following contents:user
, password islive
). The commandecho $SHELL
should now display/bin/zsh
.Context
The
zsh
shell is often used in conjunction with oh-my-zsh to provide convenient theming and extension management and configuration forzsh
. As of now, it doesn't seem possible to use suchzsh
configuration with qterminal without having buggy behavior of the prompt in new terminal instances (erroneous newlines or%
characters displayed above the prompt).It would be great if qterminal could be compatible with
zsh
configurations the same way that all other popular terminal emulators are.System Information
Notes and References
Notes:
prompt walters
in~/.zshrc
on the Debian setup without oh-my-zsh, the issue seems to disappearzsh
with the config above will only rarely make the issue appear; however, installing oh-my-zsh also seems to make it reproducible on UbuntuReferences:
zsh
and%
:PROMPT_SP
stuff in regards to the%
appearance