title: .zshrc not sourced in tmux loaded in Intellij
body: <p>So I'm encountering some very weird behavior which I cannot explain. I recently hopped on the tmux bandwagon and set up my shell configuration to automatically launch tmux when I open a terminal window. Around the same time, I started getting a bug, where opening a new terminal session would correctly launch tmux but then display:</p>
  
  <pre><code>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% 
  </code></pre>
  
  <p>Now I have a pretty in-depth configuration, with my own <code>PS1</code> which it clearly is not using. However I could fix this by simply running:</p>
  
  <pre><code>douglasparker@gryphon /home/douglasparker% source ~/.zshrc
  douglasparker@gryphon (~)
  [17-10-11 11:35:59]$ 
  </code></pre>
  
  <p>So simply sourcing zsh's run configuration fixes it and loads everything it should, which makes no sense as that should be sourced automatically but just isn't.</p>
  
  <p>I also discovered that this only happens when <em>the first tmux session is started from the terminal embedded in Intellij</em>. If I open terminal normally (or even in Android Studio) it works correctly and sources <code>~/.zshrc</code> automatically. However opening from Intellij specifically yields this bug. The interesting part is that if Intellij opens first, then any subsequent terminals opening tmux will show the same problem. But, if I open another terminal first and leave that open, then launching a terminal in Intellij works correctly.</p>
  
  <p>By "first" I mean that there is no existing tmux server. If I close exit all open tmux windows (such that <code>tmux ls</code> yields "failed to connect to server"), then if the next session I open comes from a generic terminal then I'm fine and will continue to be until <em>all</em> tmux windows are closed again. However, if the <em>first</em> tmux window comes from Intellij then this bug surfaces and will continue for <em>all</em> terminals until I exit all the tmux windows again.</p>
  
  <p>The minimum configuration to reproduce this I have found is the following <code>~/.zshrc</code> file:</p>
  
  <pre><code>#!/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" ] &amp;&amp; [ -n "${TMUX}" ]; } then
    # Open tmux immediately
    echo "Sourced ~/.zshrc: Not in tmux" &gt;&gt; tmux.log
    tmux
    exit
  else
    # Must already be within tmux
    echo "Sourced ~/.zshrc: In tmux" &gt;&gt; tmux.log
    echo hello
  fi
  </code></pre>
  
  <p>All this does is check if it is within tmux. If not, then it opens tmux, and exits after tmux stops. Opening a session within that <em>should</em> source this script a second time, and print <code>hello</code> to the console within tmux.</p>
  
  <p>If there are no tmux sessions open and I launch a normal terminal window (of if there <em>is</em> an existing tmux session from a normal terminal window and I launch a terminal in Intellij) then I get the expected output:</p>
  
  <pre><code>hello
  douglasparker@gryphon ~% cat tmux.log
  Sourced ~/.zshrc: Not in tmux
  Sourced ~/.zshrc: In tmux
  douglasparker@gryphon ~% 
  </code></pre>
  
  <p>If there are no tmux sessions open and I launch a terminal window within Intellij, then I get the output:</p>
  
  <pre><code>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% 
  </code></pre>
  
  <p>This is all printed within a tmux session in Intellij. So it is correctly sourcing the <code>~/.zshrc</code> file <em>once</em> and launching tmux, however it simply does <em>not</em> source <code>~/.zshrc</code> a second time within tmux under these very specific conditions and I have no idea why.</p>
  
  <p>I also tried changing my shell to bash temporarily and found that the issue did <em>not</em> reproduce on bash. So this problem seems to come from integration between zsh, tmux, and Intellij.</p>
  
  <p>I realize this is an incredibly specific problem, but does anyone know what could be causing this kind of issue? Looking up the zsh error didn't really help me find the cause of this. Is there something special that Intellij does with its terminal windows which might cause this behavior? Is there any documented reason why zsh would refuse to source <code>~/.zshrc</code>?</p>