为什么 ksh 的 vi-mode 在 macOS“Big Sur"的终端中出现有时会损坏编辑行? [英] Why does ksh's vi-mode in Terminal on macOS "Big Sur" sometimes corrupts the edit line?
问题描述
我注意到有时在尝试编辑历史记录中的一行以重新运行命令时,ksh 会使该行出现乱码并将光标向上移动一行.这真的很奇怪.
I noticed that sometimes when trying to edit a line in the history to re-run a command, that ksh would garble the line and move the cursor up a line. It was really bizarre.
- 首先发现只有排长队出现问题
- 调试,发现
COLUMNS
变量没有设置(很确定Terminal
是用来设置的)
- first found that it was only long lines where the problem occurred
- debugging, found that the
COLUMNS
variable was unset (pretty sureTerminal
use to set it)
我可以手动将其设置为一些大数字,但随后出现了其他问题.
I could set it by hand to some big number, but then other problems appeared.
我找不到任何方法来强制终端在调整窗口大小时更新 COLUMNS
值 - 我该怎么做?
I cannot find any way to force Terminal to update the COLUMNS
value as the window resizes - how can I do this?
推荐答案
这让我花了很长时间来追踪和修复.ksh 将在运行任何命令之前运行一个 .env
文件,因此这是您可以设置值的钩子,假设您可以找到该值.
This took me forever to track down and fix. ksh will run an .env
file before it runs any command, so that's the hook where you can set the value, assuming you can find the value.
经过高低搜索,我发现stay
会输出当前的行和列,但这些值被隐藏在其他信息的大负载中.然后我选择了 resize
选项,它只将行和列输出为两个数字.
After searching high and low, I found that stay
will output the current rows and columns, but the values are buried in a big payload of other info. Then I tripped on the resize
option, that just outputs the rows and columns as two numbers.
通过过滤输出,可以只得到列数.解决方案是将其添加到 .env 文件中,并确保 ENV
在您的 .profile 中设置.
By filtering the output, one can get just the columns number. The solution is to thus add this in a .env file, and make sure ENV
is set in your .profile.
COLUMNS=$(stty size | sed -e 's/[0-9]* \([0-9]\)/\1/')
这篇关于为什么 ksh 的 vi-mode 在 macOS“Big Sur"的终端中出现有时会损坏编辑行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!