[Matrix-SIG] Interactive shell

Pearu Peterson pearu@ioc.ee
Fri, 7 May 1999 18:22:07 +0300 (EETDST)


On Tue, 27 Apr 1999 jhauser@ifm.uni-kiel.de wrote:

> -special shell commands starting with a @
>  @pwd @cd @who @whos @logon @logoff @clean
>  These commands don't need ()

Here follows an idea:
I felt that these commands don't need '@' (and '!') either. So, below is
my hack of prefilter function. As a result I can do:
>>> ls -l
>>> dir
>>> dir shell
>>> who
etc

    def prefilter(self, line):
        sline=string.strip(line)
        i=string.find(sline,' ')
        if i<0: cline,aline=sline,''
        else: cline,aline=sline[:i],sline[i+1:]
        if line and string.strip(line)[0] == '!':
            self.handle_shell_escape(line)
            return '' # Empty string is needed here!
        elif line and string.strip(line)[0] == '?':
            return self.handle_help(line)
        elif line and string.strip(line)[0] == '@':
            return self.handle_magic(line)
        elif line and sline in
['who','dir','pwd','whos','clear','logon','logoff']: # etc
            return self.handle_magic('@'+sline)
        elif line and cline in ['cd']: # etc
            return self.handle_magic('@'+cline+'('+`aline`+')')