General point about comfort noted, but they don't do the same thing.
$^path(N) is an equivalent to your perl expression. The snippet throwaway84846 posted also removes duplicates and collapses symlinks from /usr-merge for example.
will use the latest Ruby version in ~/.local/share/gem/ruby, and it won't error out if it doesn't exist (so I can freely copy this around even to machines without Ruby, or remove Ruby, etc).
I'd like to hear viewpoints on using `~/.zprofile` versus `~/.zshrc` for setting `$PATH` on macOS. I was bothered for years that I didn't know the difference so I dived down the rabbit hole and wrote a guide [1]. In the end, I concluded:
- Use `~/.zprofile` to set the PATH and EDITOR environment variables.
- Use `~/.zshrc` for aliases and a custom prompt, or anything tweaking the appearance and behavior of the terminal.
It seems the advantage of the `~/.zprofile` file versus `~/.zshenv` is that it sets environment variables such as `$PATH` without override from macOS. It seems the `~/.zshrc` file could be used for `$PATH` but, by convention and design, is intended for customizing the look and feel of the interactive terminal.
Frankly, saying `~/.zprofile` is better than `~/.zshrc` for setting `$PATH` only "by convention and design" feels like a cop-out. Wondering if anyone knows better.
I set $PATH in ~/.zshenv. If you don't, you can't use any of your "extra stuff" in your zsh-scripts, as they do not use login or interactive sessions. And then I unset GLOBAL_RCS so the system configfiles don't override my settings.
In your guide, under ~/.zshenv, you mention that "macOS overrides this for PATH settings for interactive shells", without mentioning why or how. What's happening is that macOS sets your path in /etc/zprofile.
It seems your guide is missing a few global configfiles :) This is the order for an interactive login shell [1]:
In fact, the configfiles you mention are only loaded the way you've mentioned them, if the option GLOBAL_RCS is unset. And if GLOBAL_RCS is unset, macOS does not override your PATH, because/etc/zprofile is not loaded :)
Oops, I just remembered this, and I got the order of the last two files wrong. ${ZDOTDIR:-$HOME}/.zlogout is loaded before /etc/zlogout when logging out of a login session :)
Your assessment is correct. But it really comes down to what type of shell that's running. For an interactive shell (one you open yourself in a terminal), the run-com file (.zshrc) will be loaded, so anywhere you put it, things will seemingly work. But if you start doing some task scheduling etc, that would fail if you have set your PATH in a run-com.
I think for most of its use-cases, you could replace it with a one-liner:
alias path='echo -e ${PATH//:/\\n} '
and work with it via sort and uniq. I've had this alias in my configuration for a couple of decades now, so I'm not bashing on its usefulness though.
For me the use case was trying to understand what directories should I clean from path and if there where duplicates. Just something to help understand if my PATH on Windows was repetitive or not.
I like it! I do the steps involved in this occasionally, manually. It’s not hard but this makes it nice. Not sure I’ll use it since it is one more thing to install and remember, but the author had an itch and scratched it. Well done.
You can probably do something similar with bash, but idk.
$path is tied to $PATH and an array, so you can use it as such for some of the other things: