For zsh I use this to setup $PATH, which seems to address most of the use cases of this tool: ### Setup PATH dirs=( /usr/lib/ccache/bin # ccache ~/.local/script ~/.local/bin # My local scripts. ~/.local/gobin # GOBIN /usr/local/bin /usr/local/sbin # local takes precedence /bin /sbin /usr/bin /usr/sbin # Standard Unix /usr/pkg/bin /usr/pkg/sbin # NetBSD /usr/X11R6/bin /usr/X11R6/sbin # OpenBSD /opt/ooce/bin # illumos…
Show HN: Justpath – a simple utility to explore the PATH environment variable
21–29 of 29 posts
Re: Show HN: Justpath – a simple utility to explore the PATH environment variable
#22For zsh I use this to setup $PATH, which seems to address most of the use cases of this tool: ### Setup PATH dirs=( /usr/lib/ccache/bin # ccache ~/.local/script ~/.local/bin # My local scripts. ~/.local/gobin # GOBIN /usr/local/bin /usr/local/sbin # local takes precedence /bin /sbin /usr/bin /usr/sbin # Standard Unix /usr/pkg/bin /usr/pkg/sbin # NetBSD /usr/X11R6/bin /usr/X11R6/sbin # OpenBSD /opt/ooce/bin # illumos…
How does (N[-1]) get resolved?
% print doesnt-exist*
zsh: no matches found: doesnt-exist*
% print doesnt-exist*(N)
(doesn't print anything, pattern is just ignored)
([n]) is array indexing to get entry n; -1 gets the last entry: % print a*
a-1 a-2 a-3
% print a*([-1])
a-3
% print a*([1])
a-1
Globbing is automatically sorted by name.So putting that together, things like this:
~/.local/share/gem/ruby/*/bin(N[-1]) # Ruby
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).Re: Show HN: Justpath – a simple utility to explore the PATH environment variable
#23For zsh I use this to setup $PATH, which seems to address most of the use cases of this tool: ### Setup PATH dirs=( /usr/lib/ccache/bin # ccache ~/.local/script ~/.local/bin # My local scripts. ~/.local/gobin # GOBIN /usr/local/bin /usr/local/sbin # local takes precedence /bin /sbin /usr/bin /usr/sbin # Standard Unix /usr/pkg/bin /usr/pkg/sbin # NetBSD /usr/X11R6/bin /usr/X11R6/sbin # OpenBSD /opt/ooce/bin # illumos…
How does (N[-1]) get resolved?
Re: Show HN: Justpath – a simple utility to explore the PATH environment variable
#24Earlier quoted context omitted.
I use 'path=( ${(u)^path:A}(N-/) )' instead of that for loop
To just reduce the current entries to those that exist, I'd probably do PATH=$(perl -e 'print join ":", grep -d, split ":", $ENV{PATH}') but that's because as a 20 year perl hacker and thus connoiseur of line noise, I'd rather read that than the shell clever. (this doesn't mean the shell clever is bad, it just means I don't find -that- dialect of line noise as skimmable)
$^path(N) is an equivalent to your perl expression. The snippet throwaway84846 posted also removes duplicates and collapses symlinks from /usr-merge for example.
Re: Show HN: Justpath – a simple utility to explore the PATH environment variable
#25I’m struggling to understand the use case for this aside from just checking if your own directory is on the path.
Should it be `justpath --contains .`?
Opened issue here: https://github.com/epogrebnyak/justpath/issues/10
Re: Show HN: Justpath – a simple utility to explore the PATH environment variable
#26I’m struggling to understand the use case for this aside from just checking if your own directory is on the path.
Actually funny enough does not do that - cool possible feature Should it be `justpath --contains .`? Opened issue here: https://github.com/epogrebnyak/justpath/issues/10
Re: Show HN: Justpath – a simple utility to explore the PATH environment variable
#27Earlier quoted context omitted.
How does (N[-1]) get resolved?
(N) sets the NULL_GLOB option for that pattern: % print doesnt-exist* zsh: no matches found: doesnt-exist* % print doesnt-exist*(N) (doesn't print anything, pattern is just ignored) ([n]) is array indexing to get entry n; -1 gets the last entry: % print a* a-1 a-2 a-3 % print a*([-1]) a-3 % print a*([1]) a-1 Globbing is automatically sorted by name. So putting that together, things like this: ~/.local/share/gem/ruby/…
Re: Show HN: Justpath – a simple utility to explore the PATH environment variable
#28Earlier quoted context omitted.
(N) sets the NULL_GLOB option for that pattern: % print doesnt-exist* zsh: no matches found: doesnt-exist* % print doesnt-exist*(N) (doesn't print anything, pattern is just ignored) ([n]) is array indexing to get entry n; -1 gets the last entry: % print a* a-1 a-2 a-3 % print a*([-1]) a-3 % print a*([1]) a-1 Globbing is automatically sorted by name. So putting that together, things like this: ~/.local/share/gem/ruby/…
Thanks for explaining, looks very clever. Is this syntax part of bash?
Re: Show HN: Justpath – a simple utility to explore the PATH environment variable
#29Earlier quoted context omitted.
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 p…
Thank you! That's informative.