Awesome
Imba Shell
Interactive debugger and REPL for Imba.
Install
npm:
npm i -g imba-shell
yarn:
yarn global add imba-shell
Usage
To start using imba-shell
, run the following command:
imba-shell
To enable TypeScript, you can pass the --ts
flag:
imba-shell --ts
Note, you can also use
imbas
instead ofimba-shell
.
Multiline
To use multi-line mode, use the .editor command:
>>> .editor
This will open a multi-line editor.
Indentation
When using multi-line mode, you can use the Shift+Tab
key combination to indent the current line.
To remove a tab, use the Backspace
key.
Clear
To clear the imba-shell
, use the clear
helper:
>>> clear!
You can also use the
.clear
command.
Exit
To exit out of imba-shell
, use the exit
helper:
>>> exit!
You can also use the
.exit
command.
Imba Runtime
You may use imba-shell
as a runtime:
imbar file.imba
imbar
aliases:imba-r
,imba-runtime
,ir
.
Passing arguments to your script:
imbar craftsman.imba mail:send --help
Continously build and watch project (development purposes):
imbar --watch server.imba
flag:
--watch
alias:
-w
Creating a self executing script:
hello
#!/usr/bin/env imbar
const name = process.argv.slice(2)[0] ?? 'stranger'
console.log "Hello {name}"
If you're using Linux
, FreeBSD
or MacOS
, you can make your script executable:
chmod u+x hello
Note: when creating a script that doesn't end with
".imba"
, the Imba Runtime will clone your script into a hidden file that ends with.imba
and execute it instead of your original script. When done executing, the hidden file will be removed.
Running the script:
./hello Donald # Hello Donald
./hello # Hello stranger
API
imba-shell
can also be used as a module. Here's an example:
Imba:
import { ImbaRepl } from 'imba-shell'
# you can also pass "typescript" instead of "imba"
const repl = new ImbaRepl 'imba', 'imba> '
repl.run!
JavaScript:
const { ImbaRepl } = require('imba-shell');
/** you can also pass "typescript" instead of "imba" */
const repl = new ImbaRepl('imba', 'imba> ');
repl.run();
Note, you can pass an object of Node.js repl options in the
run
function.
History
Here's an example of how to enable the history feature:
Imba:
import { ImbaRepl } from 'imba-shell'
import os from 'os'
import path from 'path'
const repl = new ImbaRepl 'imba', 'imba> ', path.join(os.homedir!, '.my_repl_history')
repl.run!
JavaScript:
const { ImbaRepl } = require('imba-shell');
const os = require('os');
const path = require('path');
const repl = new ImbaRepl('imba', 'imba> ', path.join(os.homedir(), '.my_repl_history'));
repl.run();
You can set any valid path as your history file.
Commands
You can register commands with the registerCommand
function:
Imba:
repl.registerCommand 'goodbye', do
console.log 'Goodbye!'
this.close!
JavaScript:
repl.registerCommand('goodbye', () => {
console.log('Goodbye!');
this.close();
});
Context
You may register functions and properties to be available in the REPL using the registerCallback
function:
Imba:
const repl = new ImbaRepl
repl.registerCallback do(ctx)
ctx.foo = 'bar'
JavaScript:
const repl = new ImbaRepl();
repl.registerCallback((ctx) => {
ctx.foo = 'bar'
})
When calling foo
in the REPL, it will return bar
.
Todo
- Language Support.
- Imba.
- TypeScript.
- Code completion.
- Imba.
- TypeScript.
- Multiline Editor.
- Imba.
- TypeScript.
- Async/Await.
- Imba.
- TypeScript.
- Extensible API.
- Syntax highlighting.
- Imba.
- TypeScript.
- Compile Errors.
- Imba.
- TypeScript.
Development
Install
Install dependencies:
$ npm i
Build
Build from source:
$ npm run build
Test
Test Imba-Shell
:
$ npm run test
Security
If you discover any security related issues, please email donaldpakkies@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.