Path functions refactor/ add ~/.lib/python to PYTHONPATH

This commit is contained in:
2015-06-15 13:06:47 -07:00
parent 443f8607df
commit f94232acf0
2 changed files with 37 additions and 10 deletions

View File

@@ -1,3 +1,38 @@
function path_lines {
target=${1-PATH}
if is_zsh; then
echo ${(P)target} | tr ':' '\n'
else
echo ${!target} | tr ':' '\n'
fi
}
function _add_to_front_of_path_lines {
target=${2-PATH}
echo $1
path_lines $target | grep -Ev "^$1$"
}
function _add_to_back_of_path_lines {
target=${2-PATH}
path_lines $target | grep -Ev "^$1$"
echo $1
}
function remove_trailing_colon {
sed 's|:*$||'
}
function add_to_front_of_path {
target=${2-PATH}
export $target="$(_add_to_front_of_path_lines $1 $target | tr '\n' ':' | remove_trailing_colon)"
}
function add_to_back_of_path {
target=${2-PATH}
export $target="$(_add_to_back_of_path_lines $1 $target | tr '\n' ':' | remove_trailing_colon)"
}
function split_into_vars () {
local string IFS