Last active
December 18, 2015 14:39
-
-
Save ToJans/5799189 to your computer and use it in GitHub Desktop.
bin/elixir
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/sh | |
if [ $# -eq 0 ] || [ $1 = "--help" ] || [ $1 = "-h" ]; then | |
echo "Usage: `basename $0` [options] [.exs file] [data] | |
-v Prints version | |
-e \"command\" Evaluates the given command (*) | |
-r \"file\" Requires the given files/patterns (*) | |
-S \"script\" Finds and executes the given script (*) | |
-pr \"file\" Requires the given files/patterns in parallel (*) | |
-pa \"path\" Prepends the given path to Erlang code path (*) | |
-pz \"path\" Appends the given path to Erlang code path (*) | |
--app \"app\" Start the given app and its dependencies (*) | |
--erl \"switches\" Switches to be passed down to erlang (*) | |
--name \"name\" Makes and assigns a name to the distributed node | |
--sname \"name\" Makes and assigns a short name to the distributed node | |
--cookie \"cookie\" Sets a cookie for this distributed node | |
--hidden Makes a hidden node | |
--detached Starts the Erlang VM detached from console | |
--no-halt Does not halt the Erlang VM after execution | |
** Options marked with (*) can be given more than once | |
** Options given after the .exs file or -- are passed down to the executed code | |
** Options can be passed to the erlang runtime using ELIXIR_ERL_OPTS or --erl" >&2 | |
exit 1 | |
fi | |
readlink_f () { | |
cd "$(dirname "$1")" > /dev/null | |
filename="$(basename "$1")" | |
if [ -h "$filename" ]; then | |
readlink_f "$(readlink "$filename")" | |
else | |
echo "`pwd -P`/$filename" | |
fi | |
} | |
ERL="" | |
I=1 | |
while [ $I -le $# ]; do | |
S=1 | |
eval "PEEK=\${$I}" | |
case "$PEEK" in | |
-v|--compile|--no-halt|+iex|+compile) | |
;; | |
-e|-r|-pr|-pa|-pz|--remsh|-S) | |
S=2 | |
;; | |
--detached|--hidden) | |
ERL="$ERL `echo $PEEK | cut -c 2-`" | |
;; | |
--cookie) | |
I=$(expr $I + 1) | |
eval "VAL=\${$I}" | |
ERL="$ERL -setcookie "$VAL"" | |
;; | |
--sname|--name) | |
I=$(expr $I + 1) | |
eval "VAL=\${$I}" | |
ERL="$ERL `echo $PEEK | cut -c 2-` "$VAL"" | |
;; | |
--erl) | |
I=$(expr $I + 1) | |
eval "VAL=\${$I}" | |
ERL="$ERL "$VAL"" | |
;; | |
*) | |
break | |
;; | |
esac | |
I=$(expr $I + $S) | |
done | |
SELF=$(readlink_f "$0") | |
SCRIPT_PATH=$(dirname "$SELF") | |
if [ -f "$HOME/.elixirrc" ]; then . "$HOME/.elixirrc"; fi | |
if [ "$ELIXIR_NO_CLI" != "1" ]; then ERL="$ERL -s elixir start_cli"; fi | |
if [ -f "$SCRIPT_PATH/../releases/RELEASES" ] && [ -f "$SCRIPT_PATH/erl" ] | |
then | |
exec "$SCRIPT_PATH"/erl -env ERL_LIBS $ERL_LIBS\;"$SCRIPT_PATH/../lib" -boot elixir -noshell $ELIXIR_ERL_OPTS $ERL -extra "$@" | |
else | |
exec erl -env ERL_LIBS $ERL_LIBS\;"$SCRIPT_PATH/../lib" -noshell $ELIXIR_ERL_OPTS $ERL -extra "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment