diff --git a/zsh/configs/post/path.zsh b/zsh/configs/post/path.zsh index 48f4196..fa4086f 100644 --- a/zsh/configs/post/path.zsh +++ b/zsh/configs/post/path.zsh @@ -1,5 +1,5 @@ # ensure dotfiles bin directory is loaded first -export PATH="$HOME/.bin:/usr/local/sbin:$PATH" +PATH="$HOME/.bin:/usr/local/sbin:$PATH" # load rbenv if available if command -v rbenv >/dev/null; then @@ -7,4 +7,8 @@ if command -v rbenv >/dev/null; then fi # mkdir .git/safe in the root of repositories you trust -export PATH=".git/safe/../../bin:$PATH" +PATH=".git/safe/../../bin:$PATH" + +typeset -U PATH + +export PATH diff --git a/zsh/functions/move_to_front_of_path b/zsh/functions/move_to_front_of_path new file mode 100644 index 0000000..ac835ce --- /dev/null +++ b/zsh/functions/move_to_front_of_path @@ -0,0 +1,10 @@ +# Reorders existing entry in PATH to have it at the front +# +# move_to_front_of_path "$HOME/.bin" +# +move_to_front_of_path() { + if [[ ":$PATH:" == *":$1:"* ]]; then + PATH=$(echo $PATH | sed 's#'$1'##g' | sed s/:://g | sed s/:$//g | sed s/^://g) + PATH="$1${PATH:+":$PATH"}" + fi +}