[erlang-questions] how do I replace the Erlang shell with my own shell?

Robert Virding robert.virding@REDACTED
Fri Jan 21 13:31:59 CET 2011


I use this method for LFE. I have an lfe_boot.erl which looks like:

-module(lfe_boot).

-export([start/0]).

start() -> user_drv:start(['tty_sl -c -e',{lfe_shell,start,[]}]).


I then start erlang with script lfe:

#! /bin/bash
# Run LFE shell by default. Can add -pa if necessary.
erl "$@" -noshell -noinput -s lfe_boot start


This works well on Mac/Linux but not on Windows. One problem is that 'user_drv' does not remember which shell it was given as an argument so 'shell' is always the default. I will fix that one of these days. User_drv handles ^G and the ability to start multiple "jobs" and switch user io between them.

Robert




----- "Matthias Lang" <matthias@REDACTED> wrote:

> I want to write my own shell for Erlang. I want to be able to switch
> back and forth between my shell and the regular one without
> restarting
> the VM.
> 
> I started off writing my own autocomplete. That's easy: just call
> io:setopts([{expand_fun, Fun}]). Details are in the 'io' manpage.
> 
> But replacing the shell seems much harder. Two unsatifying
> approaches:
> 
>   1. Write a module called shell.erl, i.e. same name as the one
>      shipped by erlang.org, and use code loading to switch between my
>      version and the normal one. That would switch _all_ shell
>      instances at the same time.
> 
>   2. Hack shell.erl and make it provide two variants of shell
>      behaviour. I'll then have to merge changes forever.
> 
> There must be a better way. Digging through how input comes in, I
> find:
> 
>   First, user_sup.erl starts either of two descriptively-named
>   modules: user_drv.erl or user.erl, depending on options. The
> default
>   is user_drv, but any of '-noshell', '-oldshell', '-noinput' cause
>   'user' to be started. There's also an undocumented switch, '-user'
>   which lets you specify a module. Actual input comes from the
> 'tty_sl' port.
> 
>   user_drv.erl seems to be 600 lines of fiddling. The only feature it
>   seems to implement is the ^G menu. The module name 'shell' is
> hardcoded
>   into all of the variants of user_drv:start() which can be called
> from
>   user_sup.
> 
>   user.erl seems to be 800 lines of roughly the same thing as
>   user_drv.erl.
> 
> Conclusion: If I want to write my own shell, I also have to write a
> replacement for user_drv. Right?
> 
> Matt
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED

-- 
Robert Virding, Erlang Solutions Ltd.



More information about the erlang-questions mailing list