Recently I've started to use Alacritty as it's succinct and blazingly fast. However, when launching Alacritty from Spotlight it seems some PATH variables are missing and I can't even use nvim:

In [14]: set(x_wezterm_s)-set(x_alacrity_s)
Out[14]:
{'/Library/Apple/usr/bin',
 '/Library/TeX/texbin',
 '/opt/X11/bin',
 '/usr/local/bin',
 '/usr/local/go/bin'}

x_wezterm_s is the collection of PATHs I have in WezTerm.

After a short investigation I realized it's because I launched Alacritty with the configuration file /.config/alacritty/alacritty.yml below:

shell:
  program: /bin/zsh
  args:
    - -c
    - /Users/huzi/Scripts/macism com.apple.keylayout.ABC && exec zsh
    # more config...

And this means launching without the login option. Since the order of loading configurations in zsh is:

+----------------+-----------+-----------+------+
|                |Interactive|Interactive|Script|
|                |login      |non-login  |      |
+----------------+-----------+-----------+------+
|/etc/zshenv     |    A      |    A      |  A   |
+----------------+-----------+-----------+------+
|~/.zshenv       |    B      |    B      |  B   |
+----------------+-----------+-----------+------+
|/etc/zprofile   |    C      |           |      |
+----------------+-----------+-----------+------+
|~/.zprofile     |    D      |           |      |
+----------------+-----------+-----------+------+
|/etc/zshrc      |    E      |    C      |      |
+----------------+-----------+-----------+------+
|~/.zshrc        |    F      |    D      |      |
+----------------+-----------+-----------+------+
|/etc/zlogin     |    G      |           |      |
+----------------+-----------+-----------+------+
|~/.zlogin       |    H      |           |      |
+----------------+-----------+-----------+------+
|                |           |           |      |
+----------------+-----------+-----------+------+
|                |           |           |      |
+----------------+-----------+-----------+------+
|~/.zlogout      |    I      |           |      |
+----------------+-----------+-----------+------+
|/etc/zlogout    |    J      |           |      |
+----------------+-----------+-----------+------+

So in the interactive non-login mode stuff like /etc/zprofile and ~/.zprofile is ignored in this case. However, in /etc/zprofile macOS calls /usr/libexec/path_helper to first collect PATH from /etc/paths, /etc/paths.d and all other existing PATHs and then reorganize them by sorting alphabetically. So the missing part in my case is the --login option in alacritty.yml.

Performance issue

I also saw some people complain about path_helper as the sorting process takes a long time when you have many PATHs. Since the re-ordered PATH may change the priority of some PATHs over others, this may cause wrongly launched applications. That's also why many suggest putting all PATH under things like ~/.zshrc.