qterminal
qterminal copied to clipboard
percent (%) character displayed before prompt when zsh is used
Expected Behavior
- the terminal prompt should be displayed without any preceding newlines or characters and behave like in other terminal emulators (
konsole,gnome-terminal,tilixetc.) - qterminal should support
zshand oh-my-zsh configurations properly
Current Behavior
- when opening a new qterminal instance while having
zshset as the default shell, a color-inverted percent sign (%) will displayed above the prompt
- note: on Debian 10 buster, this happens with plain
zshandprompt adam1set in~/.zshrc - note: on Ubuntu 20.04, this happens with
zshas default shell and oh-my-zsh set up- in contrast to Debian, on Ubuntu it only occasionally happens without oh-my-zsh
Possible 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
- append to the end of
~/.zshrc:unsetopt PROMPT_SP - downsides:
- this will lead to broken newline behavior, see here
- append to the end of
-
Workaround 2
- append to the end of
~/.zshrc:setopt PROMPT_CR setopt PROMPT_SP export PROMPT_EOL_MARK="" - downsides:
- makes the
%disappear but an empty line will still be displayed above prompts in new qterminal instances
- makes the
- append to the end of
Steps to Reproduce (for bugs)
- Boot up a Debian 10 Xfce live image in a virtual machine (
*-xfce.isofrom here). All following instructions refer to the live system. - In the live system, open up a terminal and:
sudo apt update sudo apt install qterminal zsh chsh -s /bin/zsh # (the password for the live user is "live") - Create a file called
.zshrcin the current home directory (~/.zshrc) with the following contents:autoload -Uz compinit promptinit compinit promptinit prompt adam1 - Log out ("Applications" menu -> "Log Out") and back in (username is
user, password islive). The commandecho $SHELLshould now display/bin/zsh. - Open up qterminal. The issue should appear. If not, try closing and re-opening a few times.
Context
The zsh shell is often used in conjunction with oh-my-zsh to provide convenient theming and extension management and configuration for zsh. As of now, it doesn't seem possible to use such zsh 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
- Distribution & Version: Debian 10 buster
- Kernel: 4.19.0-13
- Qt Version: 5.11.3
- qtermwidget Version: 0.14.1
- lxqt-build-tools Version: 0.6.0 (in repositories, not installed)
- Package version: 0.14.1
Notes and References
Notes:
- the issue also appears on real-world Debian installations, the live image used above is just for easier reproducibility of the issue
- when setting
prompt waltersin~/.zshrcon the Debian setup without oh-my-zsh, the issue seems to disappear - on Ubuntu 20.04, just using
zshwith the config above will only rarely make the issue appear; however, installing oh-my-zsh also seems to make it reproducible on Ubuntu
References:
- I found the following in regards to
zshand%:When (non-null) output from a program doesn't include a trailing newline, zsh adds that color-inverted % to indicate that and moves to the next line before printing the prompt (source)
- a post explaining the
PROMPT_SPstuff in regards to the%appearance - a bug report in oh-my-zsh that points to a regression in another terminal emulator suffering from this
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" fiAdding 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 fiThis 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" fiAdding 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 fiThis 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.