From 086e78b68b29babf238ad7580c29b1bc3f716f88 Mon Sep 17 00:00:00 2001 From: Jack Thorne Date: Wed, 5 Nov 2014 16:15:03 -0800 Subject: [PATCH] This adds two functions to modify your PATH. Both functions check to see if the directories that will be inserted into your PATH are currently on the system. This is good for having one zshrc file and deploying it to myltiple enviroments. --- lib/functions.zsh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/functions.zsh b/lib/functions.zsh index 17f5f9cbf..15bb8e07c 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -73,3 +73,27 @@ function env_default() { env | grep -q "^$1=" && return 0 export "$1=$2" && return 3 } + +# +# Prepends the PATH varible with the input path +# +# Arguments: +# 1. path - The path that will be prepened +# Return value: +# 0 if PATH is exported to ENV +# +function prepend_path() { + [[ -d "$1" ]] && export PATH="$1":$PATH && return 0 +} + +# +# Prepends the PATH varible with the input path +# +# Arguments: +# 1. path - The path that will be prepened +# Return value: +# 0 if PATH is exported to ENV +# +function postpend_path() { + [[ -d "$1" ]] && export PATH=$PATH:"$1" && return 0 +}