通过 bash 历史记录访​​问时,屏幕会切断长命令的开头

sel*_*sid 9 osx bash gnu-screen

我在 OS X Lion 中使用默认版本的 bash 和 screen。

当我在屏幕会话中并且我向后滚动 bash 历史记录时,我找到了一个足够长的命令来换行。

我可能会先输入一些命令:

selassid@tem02:~$ ls ljmix/fiftyfifty_softsphere/T0.350/r2.43/0.565421311859c0.1
83279836214c0.144847759343/
Run Code Online (Sandbox Code Playgroud)

上面写的正确包装,但是如果我按下以通过 bash 的历史记录访​​问它,控制台只显示:

83279836214c0.144847759343/
Run Code Online (Sandbox Code Playgroud)

所以提示和命令的整个第一行都丢失了,这使得编辑变得困难;如果我滚动回第一行,它会出现,但会覆盖输出的最后一行。当我执行命令时,将显示第一行的其余部分,并且一切都按预期进行:

selassid@tem02:~$ ls ljmix/fiftyfifty_softsphere/T0.350/r2.43/0.565421311859c0.1
83279836214c0.144847759343/
total 1792
...
selassid@tem02:~$ 
Run Code Online (Sandbox Code Playgroud)

更奇怪的是,如果使用历史记录访​​问长命令但我还没有执行它,然后使用任何C-a屏幕命令,例如切换到另一个窗口然后返回,或者如果我单击当前终端窗口并回到它,历史命令现在再次正确显示。

我的PS1='\u@\h:\w$ '所以没有什么奇怪的事情发生。

有没有办法在使用历史记录时正确显示整个命令?我试过使用屏幕环绕设置,但它们只会让事情变得更糟。

stty -a 显示:

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;
Run Code Online (Sandbox Code Playgroud)

phe*_*mer 2

根据上面评论的答案,您似乎正在覆盖启动脚本之一中的 TERM 。在屏幕内时,您的术语应设置为“屏幕”,而不是“xterm-256color”。

我会查看你的 shell 启动脚本。~/.bashrc、/etc/bash/bashrc,以及可能的其他内容,例如 ~/.bash_profile 和 /etc/profile,具体取决于您如何设置所有内容。如果您看到任何 TERM="..." 设置,则需要删除这些设置。