Skip to content

Commit

Permalink
add shebang support (#274)
Browse files Browse the repository at this point in the history
* add shebang support
  • Loading branch information
Ozan Hacıbekiroğlu committed May 8, 2020
1 parent 3d7269c commit 5037994
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/tengo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func main() {
os.Exit(1)
}
} else if filepath.Ext(inputFile) == sourceFileExt {
if len(inputData) > 1 &&
bytes.Compare(inputData[:2], []byte("#!")) == 0 {
copy(inputData, "//")
}
err := CompileAndRun(modules, inputData, inputFile)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
Expand Down
22 changes: 22 additions & 0 deletions docs/tengo-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ tengo -o myapp myapp.tengo # compile 'myapp.tengo' into binary file 'myapp'
tengo myapp # execute the compiled binary `myapp`
```

Or, you can make tengo source file executable

```bash
# copy tengo executable to a dir where PATH environment variable includes
cp tengo /usr/local/bin/

# add shebang line to source file
cat > myapp.tengo << EOF
#!/usr/local/bin/tengo
fmt := import("fmt")
fmt.println("Hello World!")
EOF

# make myapp.tengo file executable
chmod +x myapp.tengo

# run your script
./myapp.tengo
```

**Note: Your source file must have `.tengo` extension.**

## Tengo REPL

You can run Tengo [REPL](https://en.wikipedia.org/wiki/Read–eval–print_loop)
Expand Down

0 comments on commit 5037994

Please sign in to comment.