From 5bb3fd8540c8c574965fc9420d3de522e6e62205 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 6 Feb 2012 09:09:30 +0000 Subject: [PATCH] path helpers are now pure bash, oh yeah ^_^ --- shell/helpers/path_helpers.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/shell/helpers/path_helpers.sh b/shell/helpers/path_helpers.sh index b731e5a..4aa33fa 100644 --- a/shell/helpers/path_helpers.sh +++ b/shell/helpers/path_helpers.sh @@ -80,7 +80,9 @@ path_prepend () { path_remove () { if [ ! -n "$1" ]; then return 2; fi if [[ ":$PATH:" == *":$1:"* ]]; then - export PATH=$(__path_clean `echo -n ":$PATH:" | sed "s;:$1;;"`) + local dirs=":$PATH:" + dirs=${dirs/:$1:/:} + export PATH=$(__path_clean $dirs) return 0 fi return 1 @@ -106,7 +108,9 @@ path_add_before () { if [ ! -n "$1" ] || [ ! -n "$2" ]; then return 2; fi if [[ ":$PATH:" == *":$2:"* ]]; then path_remove "$1" - export PATH=$(__path_clean `echo -n ":$PATH:" | sed "s;:$2;:$1:$2;"`) + local dirs=":$PATH:" + dirs=${dirs/:$2:/:$1:$2:} + export PATH=$(__path_clean $dirs) return 0 fi return 1 @@ -132,7 +136,9 @@ path_add_after () { if [ ! -n "$1" ] || [ ! -n "$2" ]; then return 2; fi if [[ ":$PATH:" == *":$2:"* ]]; then path_remove "$1" - export PATH=$(__path_clean `echo -n ":$PATH:" | sed "s;:$2;:$2:$1;"`) + local dirs=":$PATH:" + dirs=${dirs/:$2:/:$2:$1:} + export PATH=$(__path_clean $dirs) return 0 fi return 1 @@ -144,5 +150,6 @@ path_add_after () { # __path_clean ":/bin:/usr/bin:" #=> /bin:/usr/bin # __path_clean () { - echo -n "$1" | sed "s/.\(.*\)./\1/" + local dirs=${1%?} + echo ${dirs#?} }