So when I type with my new bash prompt it goes on for a while, but if the command gets to long it loops around itself and writes over bash prompt. Here is my PS1 :

PS1='\e[0;34m\A\e[m | \e[0;31m-\e[m \e[0;32m>>\e[m  '

For reference, here are the lines from a standard .bashrc relevant to PS1:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  • For reference, here are the lines from a standard .bashrc relevant to PS1: paste.ubuntu.com/7576468. My guess is that you don't have any closing brackets in your PS1. – saiarcot895 Jun 2 '14 at 23:31
  • still nothing. I tried adding brackets but all it did was add random brackets in the text I can see – mrnatbus12 Jun 3 '14 at 0:27

You need to enclose the escape sequences in \[ \]:

PS1='\[\e[0;34m\]\A\[\e[m\] | \[\e[0;31m\]-\[\e[m\] \[\e[0;32m\]>>\[\e[m\]  '

This is essentially the same as @user107425's answer but using the \e instead of \033 syntax and with the closing \[\e[m\] that resets the color to the default after the end of the prompt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.