Home > Net >  Customize bash prompt PS1
Customize bash prompt PS1

Time:12-18

I customize my bash prompt with:

PS1='\e[0;36m\u.\h
\e[0;31m $ux \e[0;92m \e[0;36m \@* \e[0;31m\w\n\e[0;92m\$ '

the output works and looks fine

but when i use a the arrowkeys to scroll in the history

after 5-10 hits of scrolling i cant move to the beginning of the line to modify the

code/command i found and

i see a part of the last command

command i execute:

$ ps aux | grep ssh

after scrolling i see

as an example in the prompt line

$ ps aux and i can only start write after the aux

so i push ctrl c for new line / cancel command

Did I forget a character after the $?

This is my Prompt:

z4o.ubuntu
   12:46 * /
$

when i copy/paste long commands i have the same problem

CodePudding user response:

You have to put invisible sequences inside \[ \] (or in \x01 \x02` bytes). Consult Bash manual.

PS1='\[\e[0;36m\]printable stuff\[\e[sequence\]'

Bash does not know how many columns the displayed characters take. \e[0;36m prints 7 characters, but does not move the cursor. You have to communicate that to Bash.

  • Related