Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pasting long lines into Mac OS X Terminal

When I paste a long string (ie, more characters than the width of the terminal window), the terminal doesn't autoscroll and put them in multiple lines.

Instead, it basically wraps onto the same line. In other words, it prints until the end of the current line and then starts printing over the existing characters from the beginning of the same line...

Here's a screenshot. Notice the characters "789abc..." at the beginning of the line.

enter image description here

I'm on 10.8.3 with Terminal 2.3. $TERM is xterm-256color.

A colleague has the exact same machine setup (though different Terminal colors and probably other configs) and he can get it to scroll.

Any ideas?

Thanks!

like image 415
propheci Avatar asked May 23 '13 05:05

propheci


1 Answers

It sounds like you don't have the nonprinting parts of your PS1 prompt string properly marked. The nonprinting parts (e.g. color change escape sequences) -- and only the nonprinting parts -- need to be marked with \[ ... \] so that the shell can tell they don't take up space on screen (and hence can tell where to wrap). For example, my prompt string is \[\e[0;32m\]\h\[\e[m\]:\W \[\e[0;34m\]\u\[\e[m\]$, which parses out as:

  • \[\e[0;32m\] - change color to green type (nonprinting, so it's wrapped in \[ ... \])
  • \h - the hostname (printing)
  • \[\e[m\] - normal print (no color) (nonprinting, hence wrapped)
  • :\W - the current directory (and delimiters) (printing)
  • \[\e[0;34m\] - change to blue type (nonprinting)
  • \u - the hostname (printing)
  • \[\e[m\] - normal type (nonprinting)
  • $ - final delimiter before the actual command
like image 130
Gordon Davisson Avatar answered Sep 24 '22 21:09

Gordon Davisson