Add_to_Path Clean Zsh.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://unix.stackexchange.com/questions/334382/find-out-what-scripts-are-being-run-by-bash-at-login | |
# prepends the given path(s) to the supplied PATH variable | |
# ex. add_to_path 'PATH' "$(go env GOPATH)/bin" | |
function add_to_path() { | |
# (P)1 path is expanded from $1 | |
# ##: Removes leading : | |
local -x pth="${(P)1##:}" | |
# (s.:.) splits the given variable at : | |
for p in ${(s.:.)2}; do | |
# %%/ Remove trailing / | |
# :P Behaves similar to realpath(3) | |
local p="${${p%%/}:P}" | |
if [[ ! "$pth" =~ "$p" ]]; then | |
pth="$p:$pth" | |
fi | |
done | |
export "$1"="${pth%%:}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment