From bbff007e920b013e80e4f3b888e856831a5e4f1e Mon Sep 17 00:00:00 2001 From: Cary Robbins Date: Sat, 7 Jun 2014 09:01:02 -0500 Subject: [PATCH] Added the path plugin. --- plugins/path/path.plugin.zsh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 plugins/path/path.plugin.zsh diff --git a/plugins/path/path.plugin.zsh b/plugins/path/path.plugin.zsh new file mode 100644 index 00000000..f985cf57 --- /dev/null +++ b/plugins/path/path.plugin.zsh @@ -0,0 +1,23 @@ +# Path Plugin +# ----------- +# Adds each line from $HOME/.path to your PATH variable. +# Environment variables will be evaluated in this file for you, so you +# can use references like $HOME/bin. +# +# Use `reload_path` to update $PATH if you change $HOME/.path + +function reload_path() { + if [ $CUSTOM_PATH ]; then + # Determine what the original path was before we modified it be removing + # our CUSTOM_PATH. This way we don't double-up entries on the path when + # manually calling reload_path. + export ORIGINAL_PATH=$(echo $PATH | sed "s|$CUSTOM_PATH||") + else + export ORIGINAL_PATH=$PATH + fi + export CUSTOM_PATH=$(eval echo $((while read x; do echo -n "$x:"; done < $HOME/.path) 2> /dev/null || echo "")) + # CUSTOM_PATH ends with a trailing colon (:) so no need to provide it here. + export PATH=${CUSTOM_PATH}${ORIGINAL_PATH} +} + +reload_path