{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/dotfiles/issues/426","labels_url":"https://api.github.com/repos/thoughtbot/dotfiles/issues/426/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/dotfiles/issues/426/comments","events_url":"https://api.github.com/repos/thoughtbot/dotfiles/issues/426/events","html_url":"https://github.com/thoughtbot/dotfiles/pull/426","id":109716011,"number":426,"title":"Don't encourage users to break their system zsh","user":{"login":"mislav","id":887,"avatar_url":"https://avatars.githubusercontent.com/u/887?v=3","gravatar_id":"","url":"https://api.github.com/users/mislav","html_url":"https://github.com/mislav","followers_url":"https://api.github.com/users/mislav/followers","following_url":"https://api.github.com/users/mislav/following{/other_user}","gists_url":"https://api.github.com/users/mislav/gists{/gist_id}","starred_url":"https://api.github.com/users/mislav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mislav/subscriptions","organizations_url":"https://api.github.com/users/mislav/orgs","repos_url":"https://api.github.com/users/mislav/repos","events_url":"https://api.github.com/users/mislav/events{/privacy}","received_events_url":"https://api.github.com/users/mislav/received_events","type":"User","site_admin":true},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-10-05T00:49:01Z","updated_at":"2015-10-05T20:22:19Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/thoughtbot/dotfiles/pulls/426","html_url":"https://github.com/thoughtbot/dotfiles/pull/426","diff_url":"https://github.com/thoughtbot/dotfiles/pull/426.diff","patch_url":"https://github.com/thoughtbot/dotfiles/pull/426.patch"},"body":"This reverts 15de0bcfee0d7a6472da048029408c5faedbae4e, which I find to be harmful advice. El Capitan finally **fixed** `/etc/zshenv` to be called `/etc/zprofile`, and now you're suggesting to users to undo that fix without understanding of what they were doing?\r\n\r\nEl Capitan's `/etc/zprofile` calls `path_helper`, which is a OS X utility to initialize the system PATH. This is meant to run for login shells before any user PATH configuration. Therefore, `/etc/zprofile` is the perfect place to call it.\r\n\r\nIf `/etc/zshenv` called `path_helper`, like it did in older versions of OS X, then it would **reorder** PATH on all subsequent invocations of zsh, such as nested shells (e.g. running `zsh` from bash) or executables with `zsh` in their shebang. This was a bug, and resulted in failed commands and much confusion to users, who thought that `path_helper` is the main culprit and some used sudo to disable this utility, further messing up their system.\r\n\r\n* * *\r\n\r\nAfter reverting the offending documentation addition, my approach to solving problem (as implemented in this PR) is as follows:\r\n\r\n* Detect broken `/etc/zshenv` (OS X versions pre-El Capitan) and suggest the user renames them to `zprofile`.\r\n* Move `.zshenv` configuration (runs too early) to `.zshrc` where it runs only once for interactive shells, and after system PATH is now set up.\r\n* Stop suggesting in documentation that users use `.zshenv`. Instead, most typical user tweaks for their environment need to be in `.zshrc`, such as PATH edits.\r\n* Support `.zshenv.local` for backwards compatibility, but issue a warning on stderr when its configuration changes PATH, and suggest to user that it gets moved to `.zshrc.local`.\r\n\r\nPlease observe more information for each of my commits from their commit messages.\r\n\r\nThe benefits of this approach:\r\n* Doesn't use `sudo` to make harmful changes to the system, except for fixing a OS X bug. El Capitan users don't have to fix anything.\r\n* Avoids excessive and unnecessary usage of `.zshenv`, thus speeding up non-interactive zsh executables.\r\n* Uses `.zshrc` as it should be used: to host configuration for interactive shells.\r\n* Helps people transition from the state where everything was messed up (OS X bug, user PATH changes in `~/.zshenv`) to the preferred long-term approach.\r\n\r\nReferences #421\r\n\r\nFurther reading:\r\n* https://github.com/sorin-ionescu/prezto/issues/381\r\n* https://github.com/Homebrew/homebrew/blob/4f990eaa65735fe306b7093aac0d71fa6e34a714/Library/Formula/zsh.rb#L51-L54\r\n* http://sourceforge.net/p/zsh/code/ci/master/tree/StartupFiles/zshenv\r\n* https://github.com/sstephenson/rbenv/wiki/Unix-shell-initialization#shell-init-files\r\n\r\n/cc @geoffharcourt @ventsislaf @reshleman"},"comment":{"url":"https://api.github.com/repos/thoughtbot/dotfiles/issues/comments/145656344","html_url":"https://github.com/thoughtbot/dotfiles/pull/426#issuecomment-145656344","issue_url":"https://api.github.com/repos/thoughtbot/dotfiles/issues/426","id":145656344,"user":{"login":"mislav","id":887,"avatar_url":"https://avatars.githubusercontent.com/u/887?v=3","gravatar_id":"","url":"https://api.github.com/users/mislav","html_url":"https://github.com/mislav","followers_url":"https://api.github.com/users/mislav/followers","following_url":"https://api.github.com/users/mislav/following{/other_user}","gists_url":"https://api.github.com/users/mislav/gists{/gist_id}","starred_url":"https://api.github.com/users/mislav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mislav/subscriptions","organizations_url":"https://api.github.com/users/mislav/orgs","repos_url":"https://api.github.com/users/mislav/repos","events_url":"https://api.github.com/users/mislav/events{/privacy}","received_events_url":"https://api.github.com/users/mislav/received_events","type":"User","site_admin":true},"created_at":"2015-10-05T20:22:19Z","updated_at":"2015-10-05T20:22:19Z","body":"[zsh's own sample `.zshenv`](http://sourceforge.net/p/zsh/code/ci/master/tree/StartupFiles/zshenv) says:\r\n\r\n> .zshenv is sourced on ALL invocations of the shell, unless the -f option is set.  **It should NOT normally contain commands to set the command search path, or other common environment variables unless you really know what you're doing.**  E.g. running \"PATH=/custom/path gdb program\" sources this file (when gdb runs the program via $SHELL), so you want to be sure not to override a custom environment in such cases.  Note also that .zshenv should not contain commands that produce output or assume the shell is attached to a tty.\r\n\r\nNow, as for your pushback:\r\n\r\n> Configuring the PATH in zprofile means it won't be loaded for non-login shells. This breaks compatibility with some terminal emulators \r\n\r\nCan you be specific about which terminal emulators you speak of? Both Terminal.app and iTerm are configured to start shells in login mode by default, be it bash or zsh. Although this is not the standard in Linux distributions, it seems to be the standard on OS X. In fact, the sole reason how bash (the default shell) gets its system path is that it consults `path_helper` in `/etc/profile`— which is only loaded in login mode. El Capitan decided to mirror that for zsh by creating an equivalent `/etc/zprofile`. Even though they screwed up in the past, right now it seems they're trying to signal us something.\r\n\r\n> […] and can cause issues with tmux or Vim shell commands.\r\n\r\nBoth tmux, vim, and any other program that you start from your shell will inherit the current environment. They don't need to additionally set PATH within their process because they already have correct PATH. When you issue shell commands within vim, they will be executed with the correct PATH environment that vim already inherited.\r\n\r\n* * *\r\n\r\nDo you have any specific example of how my approach could backfire? Because I have one example with how setting PATH in `zshenv` is sub-optimal. Observe:\r\n\r\n1. Assume `/etc/zshenv` from past broken versions of OS X;\r\n2. Assume `export PATH=HELLO:\"$PATH\"` in `~/.zshenv`;\r\n3. Assume bash is the default login shell and open a new Terminal window;\r\n4. Launch zsh by typing `zsh`. The PATH in this process is now `HELLO:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:HELLO` (notice that \"HELLO\" appears two times);\r\n5. Launch a zsh script or executable, e.g. `zsh myscript.sh`. The PATH in that process is now `HELLO:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:HELLO:HELLO` (notice that \"HELLO\" appears three times)."}}