Bash – Screen cuts off beginning of long command when accessed through bash history

bashgnu-screenosx

I'm using the default versions of bash and screen in OS X Lion.

When I'm in a screen session and I scroll back through the bash history and I come to a command that is long enough to wrap.

I might first type some command:

selassid@tem02:~$ ls ljmix/fiftyfifty_softsphere/T0.350/r2.43/0.565421311859c0.1
83279836214c0.144847759343/

That wraps properly as written above, but if I press up to access it via bash's history, the console displays only:

83279836214c0.144847759343/

So the prompt and the entire first line of the command is missing, which makes it difficult to edit; if I scroll back to the first line, it appears but it overwrites the last line of output.
When I execute the command, the rest of the first line is displayed and everything looks as expected:

selassid@tem02:~$ ls ljmix/fiftyfifty_softsphere/T0.350/r2.43/0.565421311859c0.1
83279836214c0.144847759343/
total 1792
...
selassid@tem02:~$ 

What's more curious, is that if use the history to access the long command but I don't execute it yet, then use any C-a screen command, like switching to another window and then back, or if I click out of my current terminal window and back into it, the history command is now displayed properly again.

My PS1='\u@\h:\w$ ' so there's nothing strange going on there.

Is there a way to correctly show the whole command when using the history? I've tried playing with the screen wrap settings, but they only make things worse.

stty -a shows:

speed 9600 baud; 46 rows; 80 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
    -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
    -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
    -ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
    -dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
    eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
    min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
    stop = ^S; susp = ^Z; time = 0; werase = ^W;

Best Answer

Based on the answer to the comment up above, it appears your are overriding TERM in one of your startup scripts. While inside screen, your TERM should be set to 'screen', not 'xterm-256color'.

I would look through your shell startup scripts. ~/.bashrc, /etc/bash/bashrc, and possibly others like ~/.bash_profile and /etc/profile depending on how you have everything set up. If you see any TERM="..." settings, you need to remove those.

Related Question