Here is my ZSH prompt theme
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
PROMPT='$fg[yellow]%}⚡︎ $fg[cyan]%~ $(git_prompt_info)
%{$reset_color%}→ '
ZSH_THEME_GIT_PROMPT_PREFIX="[git:"
ZSH_THEME_GIT_PROMPT_SUFFIX="]$reset_color"
ZSH_THEME_GIT_PROMPT_DIRTY="$fg[red]+"
ZSH_THEME_GIT_PROMPT_CLEAN="$fg[green]"
RPROMPT='%T'
Which looks like
When I move the $(git_prompt_info)
to RPROMPT
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
PROMPT='%T $fg[yellow]%}⚡︎ $fg[cyan]%~
%{$reset_color%}→ '
ZSH_THEME_GIT_PROMPT_PREFIX="[git:"
ZSH_THEME_GIT_PROMPT_SUFFIX="]$reset_color"
ZSH_THEME_GIT_PROMPT_DIRTY="$fg[red]+"
ZSH_THEME_GIT_PROMPT_CLEAN="$fg[green]"
RPROMPT='$(git_prompt_info)'
it looks like
See the spacing on the right? Also the arrow starts in the wrong place?
How can I fix this?
I believe $fg[color]
contains something like \e[32m
? If so, it must be enclosed in %{…%}
to indicate that this sequence has no width. But much better if you forget about the whole thing and use %F{color}
for foreground, %K{color}
for background and %f
/%k
to cancel them in place of $reset_color
. You must do
setopt promptsubst
setopt promptpercent
in order for this to work (you likely already do have this).
That gap is the width of colors, and they are the reason why you have wrong cursor position. Problem here is that zsh can’t query terminal with the question “Hey, I outputted some text, what is its width?” instead having to calculate width on its own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With