打开 PyCharm/IntelliJ IDEA 终端启动一个新的 Xorg 会话

Opening PyCharm/IntelliJ IDEA terminal starts a new Xorg session

我已经安装了 PyCharm Community Edition 2017.2.1 和 Arch Linux,默认使用 Zsh shell,i3 是我的 window 管理员。

当我在 PyCharm 中打开一个新终端 window 时,它会启动一个新的 Xorg 会话(我认为是 exec i3)并切换到一个新的 TTY。当我使用 ctrl+alt+F1 返回主会话时,我在终端中看到这些日志:

X.Org X Server 1.19.3
Release Date: 2017-03-15
X Protocol Version 11, Revision 0
Build Operating System: Linux 4.12.5-1-ARCH x86_64 
Current Operating System: Linux lenovo-laptop 4.12.8-2-ARCH #1 SMP PREEMPT Fri Aug 18 14:08:02 UTC 2017 x86_64
Kernel command line: BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=8efaeb16-67b6-4063-a130-7e1a10cb0d2f rw quiet
Build Date: 13 August 2017  09:37:50PM

Current version of pixman: 0.34.0
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.1.log", Time: Thu Sep  7 09:00:01 2017
(==) Using config directory: "/etc/X11/xorg.conf.d"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
Name Lost. Is Another notification daemon running?
[libi3] ../../i3-4.13/libi3/font.c Using Pango font monospace, size 8
[libi3] ../../i3-4.13/libi3/font.c X11 root window dictates 96.094581 DPI
i3status: trying to auto-detect output_format setting
i3status: auto-detected "i3bar"
(II) AIGLX: Suspending AIGLX clients for VT switch

当我在设置中将 shell 设置为 bash 时,它可以正常工作。 如何使终端正常运行?

转到文件 -> 设置 -> 工具 -> 终端并取消选中“Shell 集成”复选框,然后单击确定。终端应该正常运行。

这是因为选中“ Shell集成”时PyCharm(和Intellij Idea)sources a位于终端文件夹中的.zshrc文件PyCharm(和Intellij Idea)时,这就是发生这种情况。

来自 https://www.jetbrains.com/help/pycharm/terminal.html :

Shell integration:

If this option is selected, the terminal first loads a custom rc config file (located in the terminal folder under plugins of PyCharm distribution) which provides an additional set-up, and then the user's rc file. Note that presently shell integration works for Bash/sh (bashrc), zsh(zshrc) and fish shell (config.fish).

另一种解决方案是在 /opt/pycharm-professional/plugins/terminal/.zshrc:

中注释掉这段代码
if [ -n $LOGIN_SHELL ]; then
  if [ -f "$DOTDIR/.zlogin" ]; then
       source "$DOTDIR/.zlogin"
  fi
fi