0: #!/usr/bin/perl -W
1:
2: # Copyright Jacob Filipp, 2003
3: # This program is provided as is, you are free to use
4: # it in any way as long as the copyright notice is
5: # in the code
6:
7: # Yes dear monks, Quick-And-Dirty-Operating-System (DOS)
8: # is still used. Here is a tiny shell wrapper in Perl,
9: # to implement all the wonderful features that DOS lacks
10: # ,like command aliasing. Although this tiny script is
11: # meagre compared to your mathematical-script prowess
12: # it is very flexible and someone might actually like
13: # to use it ( from sheer curiosity, of course ).
14:
15: # The only fancy trick it has is the ability to launch
16: # your browser when a URL is typed ( the first case in
17: # the dispatch table. Interactive progs are run in a
18: # separate window.
19:
20: use Strict; # just for you monks, I never use it
21:
22: $SIG{ CHLD } = sub{ wait() };
23:
24: $browser_path = 'C:\Program Files\Internet Explorer\iexplore';
25: $prompt = sub{ 'Sh-wrap>' }; # can be a routine...
26: @kids = (); # forked processes
27:
28: # dispatch table with regexes, used to execute commands
29: # based on a shell command passed to it as an argument
30:
31: %dispatch = (
32:
33: '^(http://)?\S+\.(\w){3}.*$' =>sub{
34: my $kpid = fork();
35: if( $kpid == 0 ){ exec("\"$browser_path\" $_[0]") and exit}
36: else { push( @kids, $kpid ); sleep 1 }
37: # sleep needed to make sure that child acts first
38: },
39:
40: '^cd\s' => sub
41: { $_[0] =~ s!^cd\s!!; chdir($_[0]) },
42:
43: '^(exit|quit)$' => sub{ kill( 9, @kids); exit },
44:
45: '^(ftp|telnet|edit|debug).*' => sub { `start $_[0]` }
46: # interactive progs in new window
47: # will barf when running ftpd, telnetter, editors, debuggame etc...
48: );
49:
50: WH: while(1)
51: {
52:
53: print $prompt->();
54: my $line = <>;
55: chomp $line;
56:
57: foreach $regex ( keys %dispatch )
58: {
59: if( $line =~ m!$regex! )
60: { $dispatch{ $regex }->($line); next WH }
61: # permit only one match
62: }
63:
64: print `$line`;
65:
66: } In reply to DOS Wrapper by bl0rf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |