Skip to content

Instantly share code, notes, and snippets.

@uu59
Last active December 28, 2015 21:09
Show Gist options
  • Save uu59/7562320 to your computer and use it in GitHub Desktop.
Save uu59/7562320 to your computer and use it in GitHub Desktop.
#!/bin/sh
usage () {
cat <<"EOF" >&2
rbswitch
Usage:
rbswitch help
rbswitch use <version>
rbswitch versions
rbswitch build (required ruby-build)
(rbswitch install)
(rbswitch update)
Example:
rbswitch use 2.0.0-p0
rbswitch versions
How to use:
export PATH="/path/to/rbswitch/current/bin:$PATH"
EOF
exit 1
}
error () {
echo $* >&2
exit 1
}
rbswitch_url="" # TODO: should be decided
: ${RBSWITCH_DIR:="$HOME/.rbswitch"}
: ${RBSWITCH_VERSIONS:="$HOME/.rbenv/versions"}
: ${RUBYBUILD:="ruby-build"}
mkdir -p $RBSWITCH_DIR
cp $(cd $(dirname ${BASH_SOURCE:-$0}); pwd)/rbswitch $RBSWITCH_DIR/
case "$1" in
use)
if [ -z "$2" ];then
error "Ruby version required."
fi
if [ ! -d "$RBSWITCH_VERSIONS/$2" ]; then
error "$RBSWITCH_VERSIONS/$2 not exists."
fi
rm $RBSWITCH_DIR/current
ln -sf $RBSWITCH_VERSIONS/$2 $RBSWITCH_DIR/current
ln -sf $RBSWITCH_DIR/rbswitch $RBSWITCH_DIR/current/bin
;;
versions)
echo $RBSWITCH_VERSIONS/* | xargs -n1 basename
;;
build)
$RUBYBUILD $2 $RBSWITCH_VERSIONS/$2
;;
install)
curl -Lo $RBSWITCH_DIR/rbswitch $rbswitch_url
;;
update)
curl -Lo $RBSWITCH_DIR/rbswitch $rbswitch_url
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment