Only add ~/.local/bin to PATH if it exists

Without existence check, the `find` command prints a fail message to
stderr, and leaves stdout empty. This means only the prefix `:` is
appended to the `$PATH` variable.

Leaving a trailing `:` in `$PATH` is however something we really don't
want to be doing, as it makes the current directory get treated as a
part of `$PATH`.

While the `~/.local/bin` directory is generally going to exist, during
installation and in some other edge cases, it might not yet be there,
and we need to account for that.
This commit is contained in:
ItsDrike 2023-08-02 14:13:44 +02:00
parent 62912b75ba
commit 3b5ac91ae8
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0

View file

@ -8,7 +8,9 @@
# Add all folders in ~/.local/bin into PATH # Add all folders in ~/.local/bin into PATH
# Some window managers require this line to be in profile # Some window managers require this line to be in profile
# not in .zshenv # not in .zshenv
if [ -d "$HOME/.local/bin" ]; then
PATH+=":${$(find -L ~/.local/bin -type d | tr '\n' ':')%%:}" PATH+=":${$(find -L ~/.local/bin -type d | tr '\n' ':')%%:}"
fi
if [ -d "$HOME/.local/share/pyenv/shims" ]; then if [ -d "$HOME/.local/share/pyenv/shims" ]; then
PATH+=":$HOME/.local/share/pyenv/shims" PATH+=":$HOME/.local/share/pyenv/shims"