From 30d6f1b0a206ee34a7780355daeb0b942e59ee4f Mon Sep 17 00:00:00 2001 From: Ev Bogdanov Date: Fri, 17 Feb 2017 22:02:01 +0300 Subject: [PATCH] erun --- README.md | 1 + bin/erun | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 bin/erun diff --git a/README.md b/README.md index ce07ee3..7898947 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ Who is who in **bin** directory: - `cc-` CamelCase to snake_case - `d` works like `Edit , d` - `eman MODULE` shortcut for `erl -man MODULE` (displays the manual page for the Erlang module MODULE) +- `erun MODULE ARG1 ... ARGN` erlangish `go run` - `g+ WHAT` recursively grep current directory - `git+ MESSAGE` git: commit and push to master - `go+` go snippet diff --git a/bin/erun b/bin/erun new file mode 100755 index 0000000..9663517 --- /dev/null +++ b/bin/erun @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +if [ $# -eq 0 ]; then + echo 'Usage: erun mod.erl arg1 arg2 ...' + exit 1 +fi + +## FILE WITH SOURCE CODE +## ----------------------------------------------------------------------------- + +file="$1" +if [ ! -f "$file" ]; then + echo 'File not found' + exit 1 +fi + +## ERLANG MODULE TO RUN +## ----------------------------------------------------------------------------- + +mod=$(echo $file | sed -e 's/.erl//') + +## ARGUMENTS TO PASS TO THE MODULE +## ----------------------------------------------------------------------------- + +shift +args="$@" +if [ ! "$args" ]; then + # Without arguments main/0 will be called. Force main/1 + args="''" +fi + +## COMPILE AND RUN +## ----------------------------------------------------------------------------- + +erlc $file + +if [ $? -ne 0 ]; then + exit 1 +fi + +# Module should implement main/1 function +erl -noshell +pc unicode -run $mod main $args -s init stop + +## CLEAN UP +## ----------------------------------------------------------------------------- + +rm "$mod.beam"