Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

zshrc - Zsh Costumizing

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...