如何让IntelliJ终端与Oh My Zsh一起正常工作? [英] How do I get IntelliJ Terminal to work properly with Oh My Zsh?

查看:182
本文介绍了如何让IntelliJ终端与Oh My Zsh一起正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢哦我的Zsh,但它在JetBrains产品的终端中从未正常工作:

I love Oh My Zsh, but it has never worked properly in the JetBrains product's Terminals:


  • 找不到可执行文件

  • 不能使用像pyenv,sdkman,rvm这样的版本管理器

哦我的Zsh是zsh shell扩充,所以实际问题可以减少到让zsh正常工作。在阅读了一些intellij问题之后,我尝试切换所有终端配置选项(单独和整体),但是有用。

Oh My Zsh is zsh shell augmentation, so the actual problem could be reduced to just getting zsh to work properly. I have tried toggling all of the Terminal config options (individually and en masse) after reading some intellij issues, to an avail.

ref: https://github.com/robbyrussell/oh-my-zsh

推荐答案

找不到二进制文件,无法运行东西?显然是一个$ PATH问题,但是为什么以及为什么?

Can't find binaries, can't run stuff? Obviously a $PATH problem, but what and why?

我在iTerm2中回应了一条已知的好路径

I echo'd a known good path in iTerm2

/Users/starver/.sdkman/candidates/maven/current/bin:/Users/starver/.sdkman/candidates/groovy/current/bin:/Users/starver/.sdkman/candidates/gradle /current/bin:/usr/local/Cellar/pyenv-virtualenv/1.1.3/shims:/Users/starver/.pyenv/shims:/Users/starver/.pyenv/bin:/Users/starver/.cargo/斌:在/ usr / local / bin目录:在/ usr / bin中:/ bin中:/ usr / sbin目录:/ sbin目录:在/ usr /本地/去/箱中:/ opt / X11 / bin中:在/ usr /本地/ git的/ bin中: / Users / starver / bin /:/ Users / starver / code / go / bin /:/ Users / starver / .rvm / bin

和IntelliJ:

/usr/bin:/bin:/usr/sbin:/sbin

这暗示了启动文件加载问题。我的zsh手册页说负载顺序应为:

This hints at a startup file loading problem. My zsh man page says the load order should be:


  • / etc / zshenv

  • $ ZDOTDIR / .zshenv

  • 如果登录shell:


    • / etc / zprofile

    • $ ZDOTDIR / .zprofile

    • /etc/zshenv
    • $ZDOTDIR/.zshenv
    • If a login shell:
      • /etc/zprofile
      • $ZDOTDIR/.zprofile

      • / etc / zshrc

      • $ ZDOTDIR / .zshrc

      • /etc/zshrc
      • $ZDOTDIR/.zshrc

      • / etc / zlogin

      • $ ZDOTDIR / .zlogin

      • /etc/zlogin
      • $ZDOTDIR/.zlogin

      在每个文件中添加 echo 之后存在,我得到iTerm2的以下内容:

      After adding an echo to each of those files that existed, I got the following for iTerm2:

      /etc/zprofile
      /Users/starver/.zprofile
      /etc/zshrc
      /Users/starver/.zshrc
      /Users/starver/.zlogin
      

      这在IntelliJ

      and this in IntelliJ

      /etc/zshrc
      /Users/starver/.zshrc
      

      IntelliJ认为这不是登录shell。在Jetbrains终端配置中,您无法输入 / bin / zsh --login ;它没有效果。玩了一下后,我发现启用工具 - >终端 - > Shell集成使终端成为登录shell,启动文件加载故事有所改善:

      IntelliJ thinks this is not a login shell. In Jetbrains terminal configuration, you cannot enter /bin/zsh --login; it has no effect. After playing a bit, I found that turning on Tools -> Terminal -> Shell Integration makes the terminal a "login shell" and the startup file load story improved a bit:

      /etc/zshrc
      /Users/starver/.zprofile
      /Users/starver/.zshrc
      /Users/starver/.zlogin
      

      请注意,没有全局zsh启动文件,这是根本问题: / etc / zprofile 包含:

      Notice that none of the global zsh startup files and this is the root problem: /etc/zprofile contains:

      # system-wide environment settings for zsh(1)
      if [ -x /usr/libexec/path_helper ]; then
          eval `/usr/libexec/path_helper -s`
      fi
      

      哪个man path_helper解释:

      which man path_helper explains:


      path_helper实用程序读取目录/etc/paths.d和/ etc / manpaths中文件的内容.d并将其内容分别附加到PATH和MANPATH环境变量。 (除非已在环境中设置,否则不会修改MANPATH环境变量。)

      The path_helper utility reads the contents of the files in the directories /etc/paths.d and /etc/manpaths.d and appends their contents to the PATH and MANPATH environment variables respectively. (The MANPATH environment variable will not be modified unless it is already set in the environment.)

      执行 path_helper在shell启动期间至少有一次非常重要:路径 paths.d 在哪里系统和第三方安装程序定义其路径添加。不执行系统配置文件启动文件的原因是 / usr / local / bin / usr / local / go 等等不在路上。

      Executing path_helper at least once during shell startup is REALLY important: paths and paths.d are where the system and third party installers define their path additions. Not executing the system profile startup file is why /usr/local/bin, /usr/local/go, etc. are not on the path.

      我尝试了几种方法,寻找一种优雅的解决方案。显然,jediterm终端实现可防止挂钩到标准终端启动过程 - 因此它们在 / Applications / IntelliJ IDEA.app/Contents/plugins/terminal/.zshrc。我们可以修复那个实现!!将文件替换为:

      I tried several approaches, looking for an elegant solution. Apparently, the jediterm terminal implementation prevents hooking into a standard terminal startup process - so they implement startup file loading in /Applications/IntelliJ IDEA.app/Contents/plugins/terminal/.zshrc. We can fix that implementation!! Replace that file with:

      #!/bin/zsh
      
      # starver mod
      # Jetbrains uses jediterm as a java terminal emulator for all terminal uses.
      # There are some apparent limits on use:
      # - must use old-style shebang - not the #!/usr/bin/env zsh
      # - must implement the startup file loading here
      #
      # Note: original contents are in lib/terminal.jar
      
      # mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
      bindkey '^[^[[C' forward-word
      bindkey '^[^[[D' backward-word
      
      ZDOTDIR=$_OLD_ZDOTDIR
      
      if [ -n "$JEDITERM_USER_RCFILE" ]
      then
        source "$JEDITERM_USER_RCFILE"
        unset JEDITERM_USER_RCFILE
      fi
      
      if [ -n "$ZDOTDIR" ]
      then
        DOTDIR=$ZDOTDIR
      else
        DOTDIR=$HOME
      fi
      
      if [ -f "/etc/zshenv" ]; then
           source "/etc/zshenv"
      fi
      
      if [ -f "$DOTDIR/.zshenv" ]; then
           source "$DOTDIR/.zshenv"
      fi
      
      if [ -n $LOGIN_SHELL ]; then
        if [ -f "/etc/zprofile" ]; then
             source "/etc/zprofile"
        fi
        if [ -f "$DOTDIR/.zprofile" ]; then
             source "$DOTDIR/.zprofile"
        fi
      fi
      
      if [ -f "/etc/zshrc" ]; then
           source "/etc/zshrc"
      fi
      
      if [ -f "$DOTDIR/.zshrc" ]; then
           source "$DOTDIR/.zshrc"
      fi
      
      if [ -n $LOGIN_SHELL ]; then
        if [ -f "/etc/zlogin" ]; then
             source "/etc/zlogin"
        fi
        if [ -f "$DOTDIR/.zlogin" ]; then
             source "$DOTDIR/.zlogin"
        fi
      fi
      
      if [ -n "$JEDITERM_SOURCE" ]
      then
        source $(echo $JEDITERM_SOURCE)
        unset JEDITERM_SOURCE
      fi
      

      现在,在IntelliJ上终端启动,我看到

      Now, on IntelliJ terminal startup, I see

      /etc/zshrc
      /etc/zprofile
      /Users/starver/.zprofile
      /Users/starver/.shell-common
      /etc/zshrc
      /Users/starver/.zshrc
      /Users/starver/.zlogin
      

      第一个 / etc / zshrc 在插件的<$之前执行c $ c> .zshrc ,我无能为力,并没有造成任何不良副作用......

      The first /etc/zshrc is executed before the plugin's .zshrc, nothing I can do about that, and it is not causing any bad side effects...

      重复每个JetBrains产品都有一个流程,你可以随时随地享受Oh My Zsh的乐趣。

      Repeat the process for every JetBrains product and you can have the joy that is Oh My Zsh everywhere.

      注意:在 https://youtrack.jetbrains.com/issue/IDEA-194488

      这篇关于如何让IntelliJ终端与Oh My Zsh一起正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆