Skip to content

Instantly share code, notes, and snippets.

@bliotti
Created July 4, 2022 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bliotti/bad62854fe47031858fdbe9597de5f33 to your computer and use it in GitHub Desktop.
Save bliotti/bad62854fe47031858fdbe9597de5f33 to your computer and use it in GitHub Desktop.
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