Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Zsh and Perl?



Hi,

I'm very sorry if this question seems naive but I've dug a little
through the zsh source code and it seems appropriate.

I think a common task that many people are faced with is writing
little debugging tools. Frequently, they may write such a tool in a
language like Perl because it's so time efficient. Then they realize
that they have no interface for their tool so they either write their
own or they have none at all or mostly have something just like this:

    while( get_input_line_from_terminal_driver ) {
      process_input_line
    }

This makes the interface really, really bad, but the tool writer wants 
to worry about whatever they are debugging (or whatever) and not the
interface.

I've been doing a few of these tools for our research group and I've
gotten pretty good at using libraries like GNU Readline to spruce up
my interfaces, but I find myself constantly trying to emulate what shells
like Zsh already do and do very well.

I've looked at the source for tcsh, bash and now zsh and zsh *by far*
looks the best written and best suited for this task because it seems
so modular.

So I'm asking the zsh developers about the best way to solve this
problem. Basically I want to either embed perl into zsh or embed zsh
into perl, but the key is that my perl commands have to share state
from one instance of a perl interpreter.

Embed perl into zsh:
    
    Looking at the source, this looks like the most straightforward
    thing to do. It seems easy to add a 'perl_eval' command that would 
    evaluate a snippet of perl in a persistent interpreter. But I
    would want to add command into the zsh enviroment from perl so I
    can type:

	my_command my_arg1 my_arg2

    instead of

	perl_eval 'my_command my_arg1 my_arg2'

    which means you'd have to add support for calling back into zsh
    from perl.

Embed zsh into perl:

    zsh is turned into a loadable perl module and I write a script
    directly using zsh. It might look something like this:

    use Shell::Zsh;

    my $zsh = Shell::Zsh->new;

    $zsh->register_command_callback(\&my_callback);

    $zsh->other_customizations.... (add commands for completion, etc)

    $zsh->mainloop;

    sub my_callback {
       process command
    }
    
Anyway, I've gone on long enough. I'm just looking for feedback on
this general idea. Has anyone done this yet? (searching through the
source for 'perl' doesn't find much, and searching the website for
'perl' never returns). Any ideas on which option would be easier to
implement/use?

Any thoughts would be appreciated.

Jeff



Messages sorted by: Reverse Date, Date, Thread, Author