Created
September 30, 2015 14:01
-
-
Save kevsmith/175f96f2bfedf156ff8a to your computer and use it in GitHub Desktop.
Switch Erlang/Elixir scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ERL_HOME=/opt/erl | |
if [[ "${ERL_HOME}" != */ ]]; then | |
ERL_HOME=${ERL_HOME}/ | |
fi | |
LINK_DIRS="bin lib man" | |
find_active() { | |
HOME_DEPTH=`echo ${ERL_HOME} | grep -o / | wc -l` | |
TOKEN_DEPTH=`expr $HOME_DEPTH + 1` | |
if [ -d ${ERL_HOME}/bin ]; then | |
ACTIVE=`readlink ${ERL_HOME}/bin | cut -d/ -f${TOKEN_DEPTH}` | |
echo $ACTIVE | |
fi | |
} | |
activate_erlang() { | |
if [ ! -d "${ERL_HOME}$1" ]; then | |
printf "Erlang version %s not found\n" $1 | |
exit 1 | |
fi | |
for dir in $LINK_DIRS | |
do | |
rm -f ${ERL_HOME}$dir | |
done | |
for dir in $LINK_DIRS | |
do | |
ln -s ${ERL_HOME}$1/$dir ${ERL_HOME} | |
done | |
hash -r | |
echo "$1 is active" | |
hash -r | |
} | |
list_available() { | |
ACTIVE=`find_active` | |
AVAIL=`ls ${ERL_HOME} | grep -er[0-9]` | |
echo "Available Erlang versions:" | |
for vsn in $AVAIL | |
do | |
if [ "$vsn" == "$ACTIVE" ]; then | |
printf " *%s*\n" $vsn | |
else | |
printf " %s\n" $vsn | |
fi | |
done | |
} | |
if [ "$1" == "" ]; then | |
printf "Specify which Erlang version or 'list' to view available versions\n" 1>&2 | |
exit 1 | |
fi | |
case $1 in | |
list) | |
list_available | |
;; | |
*) | |
activate_erlang $1 | |
;; | |
esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
EX_HOME=/opt/elixir | |
if [[ "${EX_HOME}" != */ ]]; then | |
EX_HOME=${EX_HOME}/ | |
fi | |
LINK_DIRS="bin lib share" | |
find_active() { | |
HOME_DEPTH=`echo ${EX_HOME} | grep -o / | wc -l` | |
TOKEN_DEPTH=`expr $HOME_DEPTH + 1` | |
if [ -d ${EX_HOME}/bin ]; then | |
ACTIVE=`readlink ${EX_HOME}/bin | cut -d/ -f${TOKEN_DEPTH}` | |
echo $ACTIVE | |
fi | |
} | |
activate_elixir() { | |
if [ ! -d "${EX_HOME}$1" ]; then | |
printf "Elixir version %s not found\n" $1 | |
exit 1 | |
fi | |
for dir in $LINK_DIRS | |
do | |
rm -f ${EX_HOME}$dir | |
if [ -d ${EX_HOME}$1/$dir ]; then | |
ln -s ${EX_HOME}$1/$dir ${EX_HOME} | |
fi | |
done | |
hash -r | |
echo "$1 is active" | |
} | |
list_available() { | |
ACTIVE=`find_active` | |
AVAIL=`ls ${EX_HOME} | grep -e "[0-9].[0-9].[0-9]"` | |
echo "Available Elixir versions:" | |
for vsn in $AVAIL | |
do | |
if [ "$vsn" == "$ACTIVE" ]; then | |
printf " *%s*\n" $vsn | |
else | |
printf " %s\n" $vsn | |
fi | |
done | |
} | |
if [ "$1" == "" ]; then | |
printf "Specify which Elixir version or 'list' to view available versions\n" 1>&2 | |
exit 1 | |
fi | |
case $1 in | |
list) | |
list_available | |
;; | |
*) | |
activate_elixir $1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment