Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This happens because your .zshrc is evaluated for every new zsh process. So when you start iTerm2 it gets evaluated making your changes to $PATH, then when you start tmux that gets your modified $PATH and passes it on to a new instance of zsh inside of there and that new zsh process again evaluates the .zshrc making the changes again.</p> <p>There are several ways that you could prevent this.</p> <h2>$TMUX</h2> <p>First, to specifically prevent it from happening for shells inside of tmux you could skip making those changes if $TMUX is set:</p> <pre><code>if [[ -z $TMUX ]]; then PATH="$PATH:/foo" fi </code></pre> <h2>zprofile</h2> <p>Another option would be to move that portion of your .zshrc to your .zprofile file. This file is only evaluated by login shells. But, by default tmux starts new shells as login shells, so you'd also need to prevent tmux from doing that by adding the following to your tmux configuration:</p> <pre><code>set -g default-command /bin/zsh </code></pre> <p>You may need to adjust the path to zsh there. This would prevent tmux from starting zsh processes as login shells, so zsh inside of tmux wouldn't look at the .zprofile.</p> <h2>typeset</h2> <p>Another option somewhat along the lines of the code snippet that you linked to for preventing duplicates to be added would be to change your path modification to be something like:</p> <pre><code>typeset -aU path path=( $path /foo ) </code></pre> <p>This works because zsh automatically sets up the $path variable as an array that mirrors the content of $PATH. The -U option to typeset modifies that variable so that the entries are unique.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload