Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac Terminal.app annoying bug - How to fix it?

Video showing the problem: http://www.mentaframework.org/download/TerminalBug.mov

When I am typing on the Terminal.app and reach the end of the line, the next line starts on top of the first line, overwriting everything. Then if I use the delete key everything messes up and disappears.

I did a ssh in the same terminal to a different host and it worked fine, so can it be a problem with my shell configuration?

Watch the movie to see what happens:

Thanks,

-Sergio

like image 781
TraderJoeChicago Avatar asked Oct 02 '09 20:10

TraderJoeChicago


People also ask

Why is there a Terminal app on my Mac?

What is Terminal? Terminal is an app on your Mac that allows you to gain root-level access to your system. Think of it as the 'employee entrance' to your Mac; it lets you get backstage to change things as you see fit in what's known as the command line.

How do I stop Terminal from running on my Mac?

In the Terminal app on your Mac, choose Terminal > Quit Terminal.

Is it safe to use Terminal on Mac?

However, you should be careful when using Terminal; it's a powerful tool that has deep access to your Mac's system files. Check commands by googling them if you're not sure what they do. And if you need to delete files to save space, use an app like CleanMyMac X to do it. It's much safer!


2 Answers

You need to mark the escape codes in your PS1 variable that are setting up your coloured prompt. The shell needs to know they're not printable and then it will calculate your line wrap properly.

Here's a link to an explanation and some examples:

http://www.artemfrolov.com/articles/coloured-bash-prompt

The quick tip:

\[     begins a sequence of non-printing characters
\]     ends a sequence of non-printing characters
like image 194
Carl Norum Avatar answered Sep 22 '22 21:09

Carl Norum


http://www.artemfrolov.com/articles/coloured-bash-prompt is currently blank (as in, visit in Chrome/Firefox/Opera and see just whitespace, no content). So after studying the example here, am finding that converting:

export PS1='\e[0;32m\u@\h\e[m \D{%b %d} \t $ '

which breaks, to

export PS1='\[\e[0;32m\]\u@\h\[\e[m\] \D{%b %d} \t $ '

seems to work for me (as an additional, specific example).

Separately, and slightly off-topic, but useful (for at least my reference): to upgrade the above with helpful "compressed path" and bolded-green user@host in the prompt:

export MYPS='$(echo -n "${PWD/#$HOME/~}" | awk -F "/" '"'"'{if (length($0) > 14) { if (NF>4) print $1 "/" $2 "/.../" $(NF-1) "/" $NF; else if (NF>3) print $1 "/" $2 "/.../" $NF; else print $1 "/.../" $NF; } else print $0;}'"'"')'
export PS1='\[\e[1;32m\]\u@\h\[\e[m\] \D{%b %d} \t $(eval "echo ${MYPS}")$ '

** Edit **: this PS1 assignment (the 2nd line), imo, is much easier to read:

export MYPS='$(echo -n "${PWD/#$HOME/~}" | awk -F "/" '"'"'{if (length($0) > 14) { if (NF>4) print $1 "/" $2 "/.../" $(NF-1) "/" $NF; else if (NF>3) print $1 "/" $2 "/.../" $NF; else print $1 "/.../" $NF; } else print $0;}'"'"')'
export PS1='$USER@\[$(tput bold)\]$(hostname -s)\[$(tput sgr0)\] \D{%b %d} \t $(eval "echo ${MYPS}")$ '
like image 28
Johnny Utahh Avatar answered Sep 22 '22 21:09

Johnny Utahh