Skip to content

Set path in zshrc#307

Closed
derekprior wants to merge 1 commit intomasterfrom
dp-fix-path
Closed

Set path in zshrc#307
derekprior wants to merge 1 commit intomasterfrom
dp-fix-path

Conversation

@derekprior
Copy link
Contributor

This reverts commit 6a1bd18. On OS X,
path_helper was clobbering our expected PATH value because it is called in
/etc/zshrc.

Fixes #303. See discussion there in and in #305.

This reverts commit 6a1bd18. On OS X,
`path_helper` was clobbering our expected PATH value because it is
called in `/etc/zshrc`.

Fixes #303. See discussion there in and in #305.
@croaky
Copy link
Contributor

croaky commented Oct 3, 2014

Sounds good to me. I think we will want to separately add this per the rbenv docs:

export PATH="$HOME/.rbenv/bin:$PATH"

@gylaz
Copy link
Contributor

gylaz commented Oct 3, 2014

Reverting is best to get everything to working again. But we should consider this from the Zsh docs:

'.zshenv' is sourced on all invocations of the shell, unless the -f option is
set. It should contain commands to set the command search path, plus other
important environment variables. `.zshenv' should not contain commands that
produce output or assume the shell is attached to a tty.

And maybe figure out how we can adhere to that. Or, it's possible that we can't adhere because of the OSX path_helper issue.

@jferris
Copy link
Contributor

jferris commented Oct 6, 2014

Is that an OS X bug or a Laptop bug? https://github.com/thoughtbot/laptop/blob/master/mac#L81

@jferris
Copy link
Contributor

jferris commented Oct 6, 2014

Looks like we started moving /etc/zshenv in thoughtbot/laptop@c64806e. The discussion in sorin-ionescu/prezto#381 was given as rationale. It seems like PATH should be set in zshenv, though, so maybe that change was erroneous?

@jferris
Copy link
Contributor

jferris commented Oct 6, 2014

@derekprior @croaky if, instead of reverting this commit, you revert to having /etc/zshenv instead of /etc/zshrc, does that fix everything?

@rspeicher
Copy link
Contributor

When I went from Mountain Lion to Mavericks and restored /etc/zshenv everything worked for me as expected. But I've never set up a system with Laptop so I can't confirm if that fix will work for everyone.

@derekprior
Copy link
Contributor Author

I didnt set my machine up with laptop. I had addressed the zshenv issue by making path_helper not executable. Probably broke some other things I didnt care about, but it worked and I never noticed any other issues.

Then I did something (probably an OS update?) that restored the permissions. That's how I noticed things were broken. Then I noticed the sudo mv approach didn't fix things because /etc/zshrc does the same exact thing and was overwriting what we were doing in ~/.zshenv.

TL;DR, I think if we want to use zshenv we would want to move or delete /etc/zshrc.

@jferris
Copy link
Contributor

jferris commented Oct 6, 2014

I'm confused. What is the default state of zsh on OS X, before a laptop run? Based on the thread I linked, it sounded like /etc/zshenv existed by default and ran path_helper, and /etc/zshrc and /etc/zprofile did not exist. Is that the case? If you put your system in that state, does path_helper still mess with what we're trying to do in ~/.zshenv?

@derekprior
Copy link
Contributor Author

The default state, best I can tell, is that both etc/zshenv and /etc/zshrc exist (this is the case on my machine - can someone else verify that I didn't just screw up the sudo mv operation at some earlier date?). Those files are also identical and both call path_helper.

The earlier "fix" was to sudo mv /etc/zshenv /etc/zprofile

@jferris
Copy link
Contributor

jferris commented Oct 6, 2014

Okay; in that case, I think the real fix might be to just remove /etc/zshrc. If path_helper is rerun, it moves its managed entries back to the front of the PATH again, overriding settings from ~/.zshenv. Given that setting the PATH in ~/.zshenv is expected to work, it seems like the default /etc/zshrc is broken.

@gylaz
Copy link
Contributor

gylaz commented Oct 17, 2014

I've moved /etc/zshrc back to /etc/zshenv. My $PATH looks same in zsh, however, it's wrong in vim (and I cannot run tests from it). Tim Pope recommends moving /etc/zshenv to /etc/zshrc here. After following that advice, I can run tests from vim again.

@gylaz
Copy link
Contributor

gylaz commented Oct 19, 2014

Just verified that a brand new OS install only has /etc/zshenv.

@jferris
Copy link
Contributor

jferris commented Oct 21, 2014

@gylaz are you absolutely sure that a new install only has /etc/zshenv? Several people are saying that it's /etc/zshrc. Also, are you using tmux?

@gylaz
Copy link
Contributor

gylaz commented Oct 21, 2014

Yes. Clean install of Yosemite only had /etc/zshenv which falls in line with what Tim Pope recommends.

I do have tmux installed, but I'm not a heavy user of it -- only for long running processes.

After the clean install, I left /etc/zshenv alone, and I have not experienced issues with running specs from vim (the vim path looks correct).

@jferris
Copy link
Contributor

jferris commented Oct 21, 2014

Tim Pope's second recommendation:

Set your PATH in ~/.zshenv instead of ~/.zshrc.

Seems more in line with what the zsh docs recommend.

After the clean install, I left /etc/zshenv alone, and I have not experienced issues with running specs from vim (the vim path looks correct).

Just to verify: you did a clean install of OS X Yosemite, you're using the thoughtbot dotfiles, and everything is working correctly?

@derekprior
Copy link
Contributor Author

I've checked with a couple of Mavericks users and they all say they don't have an /etc/zshrc. I have no idea how I got that, but it appears I'm not the only one, right? Really weird.

@jferris
Copy link
Contributor

jferris commented Oct 21, 2014

@derekprior you probably got it by following advice like Tim Pope's or using laptop: https://github.com/thoughtbot/laptop/blob/96c95f1df858a7171c6a98514b69311f51ca1b14/mac#L90

@derekprior
Copy link
Contributor Author

Hm. I really thought I moved it to zpofile, but I guess I might have done this instead.

What should we do about it going forward? It seems like we should close this but should also try and help people who got into this mess by following our previous advice, right?

Do we check for /etc/zshrc on darwin and warn?

@gylaz
Copy link
Contributor

gylaz commented Oct 21, 2014

Just to verify: you did a clean install of OS X Yosemite, you're using the thoughtbot dotfiles, and everything is working correctly?

This is correct.

@jferris
Copy link
Contributor

jferris commented Oct 21, 2014

@gylaz since you're in a pretty clean situation, could you try out tmux as well? Can you try running some things in a tmux session for a Rails app, like rspec? Maybe run rspec from Vim within tmux?

I just want to make sure all the pieces are lined up correctly.

@jferris
Copy link
Contributor

jferris commented Oct 21, 2014

Do we check for /etc/zshrc on darwin and warn?

What if we check for PATH changes between ~/.zshenv and ~/.zshrc?

At the end of zshenv:

export ZSHENV_PATH="$PATH"

In zshrc:

if [ "$PATH" != "$ZSHENV_PATH"]; then
  printf "Warning: PATH changed after zshenv."
fi

@thoughtbot/shell thoughts?

@danielnolan
Copy link
Contributor

@jferris I am using thoughtbot dotfiles on both of my machines with Yosemite. I use tmux also. Everything works as expected with /etc/zshenv and no /etc/zshrc. I am able run specs with rpsec-vim and my path seems correct both in terminal and in Vim.

@jferris
Copy link
Contributor

jferris commented Oct 21, 2014

Okay, so I think this pull request can be closed. We can potentially improve the dotfiles by detecting PATH changes after zshenv.

@jferris jferris closed this Oct 21, 2014
jferris added a commit to thoughtbot/laptop that referenced this pull request Oct 21, 2014
* Using zshrc causes path_helper to override PATH from zshenv
* We set up rbenv among other things in zshenv

thoughtbot/dotfiles#307
@gylaz
Copy link
Contributor

gylaz commented Oct 22, 2014

One thing I just noticed is that there are duplicate entries in my path when I print it via vim :!echo $PATH.

Here's what my path is from the console:

/Users/greg/code/personal/go-lab/bin:.git/safe/../../bin:/Users/greg/.rbenv/shims:
/Users/greg/.bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin

And here it is from vim:

.git/safe/../../bin:/Users/greg/.rbenv/shims:/Users/greg/.bin:/usr/local/bin:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/greg/code/personal/go-lab/bin:
.git/safe/../../bin:/Users/greg/.rbenv/shims:/Users/greg/.bin:/usr/local/mysql/bin

This could be because of the path_helper bug. I haven't noticed any functionality issues.

jferris added a commit to thoughtbot/laptop that referenced this pull request Oct 22, 2014
* Using zshrc causes path_helper to override PATH from zshenv
* We set up rbenv among other things in zshenv

thoughtbot/dotfiles#307
@jferris
Copy link
Contributor

jferris commented Oct 22, 2014

I don't think path_helper will ever add something more than once. Having something on the PATH more than once frequently means the file is being loaded twice. How are you evaluating the PATH from Vim?

@gylaz
Copy link
Contributor

gylaz commented Oct 22, 2014

How are you evaluating the PATH from Vim?

@jferris I'm not sure I understand what you mean. I'm not doing any extra path loading besides what vim does. I printed out $PATH for above comment per :!echo $PATH ex command.

@jferris
Copy link
Contributor

jferris commented Oct 23, 2014

@gylaz if you put a echo zshenv in your ~/.zshenv, does it print when you run commands in Vim?

@gylaz
Copy link
Contributor

gylaz commented Oct 27, 2014

Yes, it does. I put an echo $PATH in ~/.zshenv before I modify $PATHm and when I run :!echo from vim it prints this:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/greg/code/personal/go-lab/bin:.git/safe/../../bin:/Users/greg/.rbenv/shims:/Users/greg/.bin:/usr/local/mysql/bin

@jferris
Copy link
Contributor

jferris commented Oct 27, 2014

@gylaz that explains why entries are in there twice. First, your shell runs and exports your PATH to child processes (like Vim) and then Vim's subshell does it again.

@thoughtbot/shell does that sound correct?

I think that if we end up with a situation where PATH entries are correct but sometimes duplicated, that's better than what we have now and worth going with.

@danielnolan
Copy link
Contributor

@jferris I had this problem too.. I fixed it by changing the contents of my /etc/zshenv to look like this

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

pgaspar pushed a commit to pgaspar/laptop that referenced this pull request Nov 17, 2014
* Using zshrc causes path_helper to override PATH from zshenv
* We set up rbenv among other things in zshenv

thoughtbot/dotfiles#307
@derekprior derekprior deleted the dp-fix-path branch December 20, 2014 04:28
bmorrall pushed a commit to bmorrall/laptop that referenced this pull request Dec 23, 2014
* Using zshrc causes path_helper to override PATH from zshenv
* We set up rbenv among other things in zshenv

thoughtbot/dotfiles#307
jt14den pushed a commit to ucsdlib/laptop that referenced this pull request Nov 3, 2016
* Using zshrc causes path_helper to override PATH from zshenv
* We set up rbenv among other things in zshenv

thoughtbot/dotfiles#307
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$PATH is overridden

6 participants