.zshrc 不是来自 Intellij 中加载的 tmux
.zshrc not sourced in tmux loaded in Intellij
所以我遇到了一些我无法解释的非常奇怪的行为。我最近跳上了 tmux 的潮流,并设置了我的 shell 配置,以便在我打开终端 window 时自动启动 tmux。大约在同一时间,我开始遇到一个错误,打开一个新的终端会话会正确启动 tmux,但随后会显示:
zsh-newuser-install: startup files exist, aborting.
Use the argument -f if you want to force the function to be run again.
douglasparker@gryphon /home/douglasparker%
现在我有了一个相当深入的配置,我自己的 PS1
显然没有使用。但是我可以通过简单地 运行ning:
来解决这个问题
douglasparker@gryphon /home/douglasparker% source ~/.zshrc
douglasparker@gryphon (~)
[17-10-11 11:35:59]$
所以简单地采购 zsh 的 运行 配置修复它并加载它应该加载的一切,这没有意义,因为它应该自动采购但不是。
我还发现,只有当 第一个 tmux 会话从 Intellij 中嵌入的终端启动时才会发生这种情况。如果我正常打开终端(甚至在 Android Studio 中),它会正常工作并自动获取 ~/.zshrc
。然而,从 Intellij 打开特别会产生这个错误。有趣的是,如果 Intellij 首先打开,那么任何后续打开 tmux 的终端都会显示同样的问题。但是,如果我先打开另一个终端并保持打开状态,则在 Intellij 中启动终端可以正常工作。
"first" 我的意思是没有现成的 tmux 服务器。如果我关闭退出所有打开的 tmux windows(这样 tmux ls
产生 "failed to connect to server"),那么如果我打开的下一个会话来自通用终端那么我很好并且会继续直到 all tmux windows 再次关闭。但是,如果 first tmux window 来自 Intellij,那么这个错误会浮出水面,并将继续 all 终端,直到我退出所有 tmux再次windows。
我找到的重现此文件的最低配置是以下 ~/.zshrc
文件:
#!/bin/bash
# If this is a raw terminal, just open tmux and then exit
# The inner session will re-source this script and load the configuration
if ! { [ "${TERM}" = "screen" ] && [ -n "${TMUX}" ]; } then
# Open tmux immediately
echo "Sourced ~/.zshrc: Not in tmux" >> tmux.log
tmux
exit
else
# Must already be within tmux
echo "Sourced ~/.zshrc: In tmux" >> tmux.log
echo hello
fi
所有这一切只是检查它是否在 tmux 中。如果没有,则打开 tmux,并在 tmux 停止后退出。在该 中打开一个会话应该 再次获取此脚本,并在 tmux 中将 hello
打印到控制台。
如果没有打开的 tmux 会话并且我启动了一个普通终端 window(如果 是 来自普通终端的现有 tmux 会话 window 然后我在 Intellij 中启动了一个终端)然后我得到了预期的输出:
hello
douglasparker@gryphon ~% cat tmux.log
Sourced ~/.zshrc: Not in tmux
Sourced ~/.zshrc: In tmux
douglasparker@gryphon ~%
如果没有打开 tmux 会话并且我在 Intellij 中启动终端 window,那么我得到输出:
zsh-newuser-install: startup files exist, aborting.
Use the argument -f if you want to force the function to be run again.
douglasparker@gryphon /home/douglasparker% cat tmux.log
Sourced ~/.zshrc: Not in tmux
douglasparker@gryphon /home/douglasparker%
这都是在 Intellij 的 tmux 会话中打印的。所以它正确地采购 ~/.zshrc
文件 once 并启动 tmux,但是它只是 not source ~/.zshrc
秒在这些非常特殊的条件下 tmux 中的时间,我不知道为什么。
我还尝试将我的 shell 暂时更改为 bash,发现问题 没有 在 bash 上重现。所以这个问题似乎是zsh、tmux和Intellij之间的集成问题。
我意识到这是一个非常具体的问题,但是有人知道是什么导致了这种问题吗?查找 zsh 错误并没有真正帮助我找到原因。 Intellij 对其终端 windows 有什么特别之处可能会导致这种行为吗? zsh 拒绝来源 ~/.zshrc
?
是否有任何记录在案的原因
基于 https://youtrack.jetbrains.com/issue/IDEA-165272,在 Intellij 中,取消选中设置 > 工具 > 终端 > Shell 集成为我解决了这个问题。
我不知道该设置的实际作用,也找不到任何相关文档,但禁用它可以解决问题。
谢谢CrazyCoder,你救了命!
所以我遇到了一些我无法解释的非常奇怪的行为。我最近跳上了 tmux 的潮流,并设置了我的 shell 配置,以便在我打开终端 window 时自动启动 tmux。大约在同一时间,我开始遇到一个错误,打开一个新的终端会话会正确启动 tmux,但随后会显示:
zsh-newuser-install: startup files exist, aborting.
Use the argument -f if you want to force the function to be run again.
douglasparker@gryphon /home/douglasparker%
现在我有了一个相当深入的配置,我自己的 PS1
显然没有使用。但是我可以通过简单地 运行ning:
douglasparker@gryphon /home/douglasparker% source ~/.zshrc
douglasparker@gryphon (~)
[17-10-11 11:35:59]$
所以简单地采购 zsh 的 运行 配置修复它并加载它应该加载的一切,这没有意义,因为它应该自动采购但不是。
我还发现,只有当 第一个 tmux 会话从 Intellij 中嵌入的终端启动时才会发生这种情况。如果我正常打开终端(甚至在 Android Studio 中),它会正常工作并自动获取 ~/.zshrc
。然而,从 Intellij 打开特别会产生这个错误。有趣的是,如果 Intellij 首先打开,那么任何后续打开 tmux 的终端都会显示同样的问题。但是,如果我先打开另一个终端并保持打开状态,则在 Intellij 中启动终端可以正常工作。
"first" 我的意思是没有现成的 tmux 服务器。如果我关闭退出所有打开的 tmux windows(这样 tmux ls
产生 "failed to connect to server"),那么如果我打开的下一个会话来自通用终端那么我很好并且会继续直到 all tmux windows 再次关闭。但是,如果 first tmux window 来自 Intellij,那么这个错误会浮出水面,并将继续 all 终端,直到我退出所有 tmux再次windows。
我找到的重现此文件的最低配置是以下 ~/.zshrc
文件:
#!/bin/bash
# If this is a raw terminal, just open tmux and then exit
# The inner session will re-source this script and load the configuration
if ! { [ "${TERM}" = "screen" ] && [ -n "${TMUX}" ]; } then
# Open tmux immediately
echo "Sourced ~/.zshrc: Not in tmux" >> tmux.log
tmux
exit
else
# Must already be within tmux
echo "Sourced ~/.zshrc: In tmux" >> tmux.log
echo hello
fi
所有这一切只是检查它是否在 tmux 中。如果没有,则打开 tmux,并在 tmux 停止后退出。在该 中打开一个会话应该 再次获取此脚本,并在 tmux 中将 hello
打印到控制台。
如果没有打开的 tmux 会话并且我启动了一个普通终端 window(如果 是 来自普通终端的现有 tmux 会话 window 然后我在 Intellij 中启动了一个终端)然后我得到了预期的输出:
hello
douglasparker@gryphon ~% cat tmux.log
Sourced ~/.zshrc: Not in tmux
Sourced ~/.zshrc: In tmux
douglasparker@gryphon ~%
如果没有打开 tmux 会话并且我在 Intellij 中启动终端 window,那么我得到输出:
zsh-newuser-install: startup files exist, aborting.
Use the argument -f if you want to force the function to be run again.
douglasparker@gryphon /home/douglasparker% cat tmux.log
Sourced ~/.zshrc: Not in tmux
douglasparker@gryphon /home/douglasparker%
这都是在 Intellij 的 tmux 会话中打印的。所以它正确地采购 ~/.zshrc
文件 once 并启动 tmux,但是它只是 not source ~/.zshrc
秒在这些非常特殊的条件下 tmux 中的时间,我不知道为什么。
我还尝试将我的 shell 暂时更改为 bash,发现问题 没有 在 bash 上重现。所以这个问题似乎是zsh、tmux和Intellij之间的集成问题。
我意识到这是一个非常具体的问题,但是有人知道是什么导致了这种问题吗?查找 zsh 错误并没有真正帮助我找到原因。 Intellij 对其终端 windows 有什么特别之处可能会导致这种行为吗? zsh 拒绝来源 ~/.zshrc
?
基于 https://youtrack.jetbrains.com/issue/IDEA-165272,在 Intellij 中,取消选中设置 > 工具 > 终端 > Shell 集成为我解决了这个问题。
我不知道该设置的实际作用,也找不到任何相关文档,但禁用它可以解决问题。
谢谢CrazyCoder,你救了命!