0

I have some settings in my .zshrc file that should run in a regular terminal, but not when the terminal is called from IntelliJ.

I am currently using IntelliJ IDEA 2021.3.3 Ultimate Edition on Windows 11, and I am using wsl2 version 2.1.5.0.

Basically, I don't want tmux to launch in an IntelliJ terminal, so I used the solution from this question.

In order to do that, on a normal Linux machine, I have added the following block to my rc file :

if ps -p $PPID | grep -iq java; then
#config for intelliJ execution
else
#config for regular execution
fi

However, the problem on wsl2 is that both commands ps -p $PPID return the same output and that ps aux doesn't show any java process on either terminals. This makes sense, as IntelliJ is a windows process, and wsl2 has no knowledge of its existence.

I also know that IntelliJ sets the variable TERMINAL_EMULATOR to JetBrains-JediTerm when invoking a new shell. However, for my version at least, the allocation does not work out of the box for wsl.

Here are the steps I tried to circumvent the issue :

  • I set up my environment variables and updated WSLENV=TERMINAL_EMULATOR in my windows settings
    • I can retrieve the value of the variable in my IntelliJ terminal. The problem is that the value is global to the system, so any new terminal I open will have the value defined.
  • In the Tools>Terminal section of the IntelliJ settings, I tried updating the Shell path value to wsl.exe --distribution Ubuntu-22.04 zsh -c "isIntellij=true zsh"
    • This works with bash (when writing wsl.exe --distribution Ubuntu-22.04 bash -c "isIntelliJ=true bash"), but not with zsh for some reason.
    • I've also tried the following combinations with the same result : zsh -c "export isIntellij=true; zsh", bash -c "export isIntellij=true; zsh", using the zsh -i flag

Is there any lead I've not explored ? Also, it should be noted that I can't update IntelliJ (this is my perpetual fallback license).

1 Answer 1

0

Ok, so after fumbling around, I figured it out.

Basically, my 2nd attempt was on the right track. The only caveat : you have to restart intelliJ for it to update the value of the isIntellij variable.

Steps to reproduce :

  • Add the following code to your .zshrc file :

    if [[ "$isIntelliJ" = "true" ]]; then
    #config for intelliJ execution
    else
    #config for regular execution
    fi
    
  • Open IntelliJ, go in the Tools>Terminal settings

  • Update the Shell path value to wsl.exe --distribution Ubuntu-22.04 zsh -c "isIntelliJ=true zsh"

  • Restart IntelliJ

Update: It seems you have to do that for every existing project as otherwise IntelliJ will load the default wsl path, which is really tedious. I will update if I find a more definitive solution, as as far as I can tell, there is no xml file available for default terminal settings

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .