zsh - 如何在执行无效命令时自动重置会话;避免 "Broken Pipe" 消息

zsh - How can I do automatic resetting of the session on invalid command execution; avoiding "Broken Pipe" message

我在 iTerm2 上使用 oh-my-zsh。每次执行无效命令时,zsh 都会显示 "Broken Pipe" 消息。请看下面的截图:

我必须通过按 "command+R" (Macbook) 手动重置会话才能恢复提示并再次开始使用 shell。

我希望 zsh/iTerm2 在执行无效命令时自动恢复提示。

我可以在 zsh 中做什么setting/configuration来实现所需的行为吗?

编辑: 我的 iTerm 配置为使用 zsh 而不是登录 shell。

在做了一些 research 之后,我找到了解决方案。

我们可以使用 zsh 的 ERROR 陷阱重新启动 shell,以防命令出错或命令以错误状态退出。

我在 .zshrc 文件中写了以下内容:

TRAPZERR() {
if [[ $? -gt 0 ]];then
     /Applications/iTerm.app/Contents/MacOS/iTerm2 --launch_shell
fi
}

成功了!!