有时我的 zsh 会弄乱行尾

nob*_*be4 5 command-line zsh command newlines

我有这个奇怪的问题,我找不到根源,也找不到解决方案。

“有时”我的 zsh 搞砸了,并以一种有趣的方式开始显示行尾:

截屏

正如你所看到的,换行符被忽略了,我%在行尾感到很有趣。

您知道什么可能导致这种情况以及如何解决吗?

注意:我正在运行 OS X,Iterm2 和 Tmux 中的 zsh。

Tho*_*key 5

屏幕截图显示了所谓的“楼梯”,其中从计算机发送到终端的换行符不会被终端驱动程序自动转换为回车/换行。

在运行临时修改终端模式但未成功恢复原始模式的程序后,您会看到这一点。由于将二进制文件显示到屏幕上,您永远不会看到这种情况。

您可以在某些 shell 上产生这种行为(其他的,例如tcsh在每个命令之后重置终端模式)。这是一个使用示例dash

$ stty -a
speed 38400 baud; rows 40; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
$ stty -onlcr
$ stty -a
         speed 38400 baud; rows 40; columns 80; line = 0;
                                                         intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
                                              eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
                                            werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
                   -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
                                                                            -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
                                                                          -iuclc -ixany -imaxbel -iutf8
                       opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
                       isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
                  echoctl echoke
                                $ 
Run Code Online (Sandbox Code Playgroud)

根据reset建议,该命令将重置终端模式,但也会重置终端本身的功能。你也可以使用

stty sane
Run Code Online (Sandbox Code Playgroud)

或更具体地说

stty onlcr
Run Code Online (Sandbox Code Playgroud)

reset涉及最少的打字。

进一步阅读: