erun
This commit is contained in:
parent
23c5e3a66a
commit
30d6f1b0a2
2 changed files with 48 additions and 0 deletions
|
|
@ -91,6 +91,7 @@ Who is who in **bin** directory:
|
||||||
- `cc-` CamelCase to snake_case
|
- `cc-` CamelCase to snake_case
|
||||||
- `d` works like `Edit , d`
|
- `d` works like `Edit , d`
|
||||||
- `eman MODULE` shortcut for `erl -man MODULE` (displays the manual page for the Erlang module MODULE)
|
- `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
|
- `g+ WHAT` recursively grep current directory
|
||||||
- `git+ MESSAGE` git: commit and push to master
|
- `git+ MESSAGE` git: commit and push to master
|
||||||
- `go+` go snippet
|
- `go+` go snippet
|
||||||
|
|
|
||||||
47
bin/erun
Executable file
47
bin/erun
Executable file
|
|
@ -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"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue