-1

I was colorizing my prompt. I did it in .zshrc file .zshrc

  PROMPT=$'%B%{\e[38;2;224;108;117m('                                                                                                                                 
  PROMPT+=$'%{\e[38;2;229;192;123m%n'                                                                                                                                 
  PROMPT+=$'%{\e[38;2;97;175;239m%(#..@)'                                                                                                                           
  PROMPT+=$'%{\e[38;2;152;195;121m%m'                                                                                                                                 
  PROMPT+=$'%{\e[38;2;224;108;117m)-['                                                                                                                                
  PROMPT+=$'%{\e[38;2;198;120;221m%~'                                                                                                                                 
  PROMPT+=$'%{\e[38;2;224;108;117m]'                                                                                                                                  
  PROMPT+=$'%{\e[38;2;224;108;117m$:'                                                                                                                                 
  PROMPT+=$'%b%{$reset_color'

and i am getting colors i want but if i enter a long command like
cd Desktop
i am getting this:

cd Desktopkali)-[~]$:cd

this is that i want:

(enes-can@kali)-[~]$:cd Desktop

How can i fix this.

Hapalua
  • 13
  • 4
  • Use Grammarly to avoid your very basic spelling mistakes. – HappyFace Jan 06 '21 at 13:30
  • @Only0Night : If I count correctly, you have in your prompt string 10 opening `%{` and not a single closing `%}`. Or are all the missing ones provided by `$reset_color`? – user1934428 Jan 07 '21 at 08:23

1 Answers1

1

You are overcomplicating this; you appear not to be closing any of the %{ to properly mark an ANSI escape sequence as a zero-width item for purposes of calculating the prompt length and cursor position, but you don't need raw ANSI escape sequences in the first place.

This does require you to represent your RGB triplets in hexadecimal first, though.

PROMPT='%B%F{#e06c75}('   # 224 == 0xe0, 108 == 0x6c, 117 == 0x75
PROMPT+='%F{...}%n'                                                                                                                                 
PROMPT+='%F{...}%(#..@)'                                                                                                                           
PROMPT+='%F{...}%m'                                                                                                                                 
PROMPT+='%F{...})-['                                                                                                                                
PROMPT+='%F{...}%~'                                                                                                                                 
PROMPT+='%F{...}]'                                                                                                                                  
PROMPT+='%F{...}$:'                                                                                                                                 
PROMPT+='%b%f' 

The benefit of using %F is that zsh already knows that the byte sequence it produces should not contribute to the prompt length, relieving you of the burden of using %{ ... %} everywhere.

chepner
  • 497,756
  • 71
  • 530
  • 681