Skip to content

Instantly share code, notes, and snippets.

@richo
Created April 22, 2013 01:57
Show Gist options
  • Select an option

  • Save richo/5431953 to your computer and use it in GitHub Desktop.

Select an option

Save richo/5431953 to your computer and use it in GitHub Desktop.
function _php() {
case "$1" in
-h|--help)
echo "usage: _php [version] [opts]"
;;
-v|--version)
echo "_php version 0.0.0"
;;
system)
_php_reset
;;
"")
local star
for i in ${__php_LIST}; do
if [ "$i" = "${php_ROOT}" ]
then
star="*"
else
star=" "
fi
echo " $star $(basename $i)"
done
;;
*)
for i in ${__php_LIST}; do
if [[ `basename "$i"` == *$1* ]]
then
shift
_php_use "$i" "$*"
return "$?"
fi
done
echo "_php: unknown php: $1"
;;
esac
}
function _php_use() {
if [ -n ${php_ROOT} ]
then
_php_reset
fi
export php_ROOT="$1"
if [ -n "${_php_fragment}" ]
then
export PATH=$(echo "${PATH}"| sed -e "s|${_php_fragment}||" -e "s|::|:|" -e "s|^:||" -e "s|:$||")
fi
_php_fragment="${_php_fragment}:${php_ROOT}/bin"
export PATH="${_php_fragment}:$PATH"
}
function _php_reset() {
if [ -n "${_php_fragment}" ]
then
export PATH=$(echo "${PATH}"| sed -e "s|${_php_fragment}||" -e "s|::|:|" -e "s|^:||" -e "s|:$||")
fi
_php_fragment=''
if [ -n "${php_ROOT}" ]
then
unset php_ROOT
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment