1

My current .bash_profile is equal to the below. I add some color and add a command that outputs whether or not I am in a git repository to my PS1 for my bash profile.

ORIG=$PS1
PS1="\[${txtund}${green}\]LOCAL\[\[${reset}\]";
PS1+="\$(prompt_git \"${white} on ${violet}\")";
PS1+="\[${reset}\]";
PS1+=" - \u\$: ";

The problem is that when I run long commands, it is rewriting over the line. I want to word wrap my commands so that as I write they go to the next line. What do I need to wrap the PS1 in for this to occur?

UPDATE -

ORIG=$PS1
PS1="\[${txtund}${green}\]LOCAL\[\[${reset}\]";
PS1+="\$(prompt_git \"\[${white}\] on \[${violet}\]\")";
PS1+="\[${reset}\]";
PS1+=" - \u\$: ";

I have increased the number of escapes as per the comment from below. The wrap is still not working. Any other suggestions?

  • 1
    I see you have enclosed most of the non-printing characters in \[ \] except the colours on the second line. Try enclosing them as well. – muru Apr 22 '15 at 16:48
  • @muru I have updated the file. Still not working. Any other ideas? – ILikeTurtles Apr 22 '15 at 17:25
  • @muru I have fixed it. – ILikeTurtles Apr 22 '15 at 17:29
2
ORIG=$PS1
PS1="\[${txtund}${green}\]LOCAL\[\[${reset}\]";
PS1+="\$(prompt_git \"\[${white}\] on \[${violet}\]\")";
PS1+="\[${reset}\]";
PS1+="\[ - \u\$: \]";

I have escaped both the colors as well as the final line of text. This solves my issue. It is through using [ ] and escaping colors as well as text, I am able to word wrap my commands in bash correctly.

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.