Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question
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 at 16:48
    
@muru I have updated the file. Still not working. Any other ideas? –  Aaron Apr 22 at 17:25
    
@muru I have fixed it. –  Aaron Apr 22 at 17:29

1 Answer 1

up vote 1 down vote accepted
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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