Long commands in bash terminal overwrites my prompt, instead of new line

When I'm in Terminal and I type a long command or something, instead of the Terminal continuing the command onto the next line, it starts overwriting my username@host prompt. Does anyone know how to fix this?

MacBook Pro with Retina display, OS X Mountain Lion (10.8.4)

Posted on Aug 18, 2013 7:29 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 18, 2013 9:12 AM

It must be something to do with the escaped color codes. Try using tput in the following way (this is approximately the colors you have in the above definition):


PS1="\[$(tput bold)\]\[$(tput setaf 5)\]malt@\[$(tput setaf 2)\]xxx: $ \[$(tput sgr0)\]"

10 replies

Aug 18, 2013 2:35 PM in response to altjxx

NOTE: What fixed your problem was putting any non-printing characters between \[ ... \] escaped square brackets. This is how you tell the promote NOT to count those characters so that it knows when to go to a newline, and not to count those characters when editing a command line.


The use of tput is fine, but your raw escape sequence would have also been fine, if you have wrapped it in \[ ... \]



PS1='\[\033[1;37\]malt@\[\033[1;32m\]xxx: \[\033[0;00m\]\$ '

Aug 18, 2013 8:17 AM in response to altjxx

What's the specific line you added to the profile to add the colors? There may be a syntax issue somewhere.


Alternatively, if you think the syntax is ok, then you can always escape a return character when you get to the end of the window for a long command. To do this, at any point in the command string you can type a back-slash, and then press Enter to get to a new line and continue the command, such as the following to run the deeply buried "lsregister" command (you can copy these four lines and paste them in the Terminal, and the "lsregister" command will be run):


/System/Library/Frameworks/CoreSe\
rvices.framework/Versions/A/Framewo\
rks/LaunchServices.framework/Versio\
ns/A/Support/lsregister

Aug 18, 2013 9:10 PM in response to BobHarris

Yep, that's exactly correct man. I just also fixed another issue too by doing this.


The other issue that I had is that if I tried to scroll to a previous command and hit Home to go to the beginning of that command, it'd jump only to like half the command... It'd be pretty screwed up.


So thank you for helping me fix two of the problems I've been experiencing 🙂

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Long commands in bash terminal overwrites my prompt, instead of new line

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.