Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add_to_Path Clean Zsh.
# 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