romkatv / powerlevel10k

A Zsh theme
MIT License
45.77k stars 2.16k forks source link

Instant Prompt doesn't fit to terminal width initially #2764

Open rjeye opened 5 days ago

rjeye commented 5 days ago

For a split second, the right side of the prompt appears in the middle of the terminal (in my settings, it currently shows the time taken for the command) before settling down correctly. This happens every time I open a new terminal. Looks like it has mostly to do with the Instant Prompt. Any pointers as to what I can fix ? My .zshrc is pasted below for reference. Attached the current .p10k.zsh as well. TIA!

p10k.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

# Set the directory we want to store zinit and plugins
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"

# Download Zinit, if it's not there yet
if [ ! -d "$ZINIT_HOME" ]; then
   mkdir -p "$(dirname $ZINIT_HOME)"
   git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi

# Source/Load zinit
source "${ZINIT_HOME}/zinit.zsh"

# Add in Powerlevel10k
zinit ice depth=1; zinit light romkatv/powerlevel10k

# # Add in zsh plugins
zinit light Aloxaf/fzf-tab
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light trystan2k/zsh-tab-title
zinit light MichaelAquilina/zsh-auto-notify
zinit light srijanshetty/zsh-pip-completion
# zinit light zsh-users/zsh-autosuggestions

# # Add in snippets
zinit snippet OMZP::git
zinit snippet OMZP::sudo
zinit snippet OMZP::archlinux
zinit snippet OMZP::aws
zinit snippet OMZP::kubectl
zinit snippet OMZP::kubectx
zinit snippet OMZP::command-not-found

# Load completions
autoload -Uz compinit && compinit

zinit cdreplay -q

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

# # Keybindings
# bindkey -e
bindkey '^[[1;5C' emacs-forward-word
bindkey '^[[1;5D' emacs-backward-word
bindkey '^p' history-search-backward
bindkey '^n' history-search-forward
bindkey '^[w' kill-region

# # History
HISTSIZE=5000
HISTFILE=~/.zsh_history
SAVEHIST=$HISTSIZE
HISTDUP=erase
setopt appendhistory
setopt sharehistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt [hist_find_no_dups](url)

# # Completion styling
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu select
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath'
zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'ls --color $realpath'

# # Shell integrations
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
romkatv commented 5 days ago

Probably a bug in the terminal, or perhaps in the window manager.

rjeye commented 4 days ago

I see. Is there still some way this could be fixed by manually editing the cached instant prompt generated ? It could be because of the terminal (Tilix) could be sending the wrong value of the width at the instant it starts. Window manager is the default tiling window manager that ships with PopOS but might not be the source of the bug since the issue appears on both the regular windowed terminal as well as the built-in Quake mode that Tilix supports.

romkatv commented 4 days ago

Could you verify that the issue isn't caused by something else loaded your zsh startup files? To do that, replace your .zshrc with this:

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
if [[ ! -e ~/powerlevel10k ]]; then
  git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
fi
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

Then restart your terminal twice.