version 1.22, 2016/09/09 16:25:37 |
version 1.23, 2016/09/10 08:00:12 |
|
|
|
|
# is $1 missing from $2 (or PATH) ? |
# is $1 missing from $2 (or PATH) ? |
function no_path { |
function no_path { |
eval _v="\$${2:-PATH}" |
eval _v="\$${2:-PATH}" |
case :$_v: in |
case :$_v: in |
*:$1:*) return 1;; # no we have it |
*:$1:*) return 1;; # no we have it |
esac |
esac |
return 0 |
return 0 |
} |
} |
# if $1 exists and is not in path, append it |
# if $1 exists and is not in path, append it |
function add_path { |
function add_path { |
[[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1" |
[[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1" |
} |
} |
# if $1 exists and is not in path, prepend it |
# if $1 exists and is not in path, prepend it |
function pre_path { |
function pre_path { |
[[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}" |
[[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}" |
} |
} |
# if $1 is in path, remove it |
# if $1 is in path, remove it |
function del_path { |
function del_path { |
no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: | |
no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: | |
sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"` |
sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"` |
} |
} |