| Term-ShellKit documentation | Contained in the Term-ShellKit distribution. |
Term::ShellKit::Commands - Basic shell functions
> perl -MTerm::ShellKit -eshell
Term::ShellKit: Starting interactive shell
Term::ShellKit> eval join ', ', 1 .. 10
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Term::ShellKit> alias incr eval $i += 1
Term::ShellKit> incr
1
Term::ShellKit> incr
2
Term::ShellKit> help
NAME
Term::ShellKit - Generic Perl command-line environment
...
Term::ShellKit> exit
The following commands are available.
Manipulates Term::ShellKit aliases.
Prints the provided argument.
Run some Perl using eval.
Run an external program with Perl's qx operator.
Exit the shell.
Uses the pod2text script to display documentation for a Perl module.
Load a ShellKit package.
Try "kit Dev" to load the Dev kit, or "help kit Dev" to learn more about it.
Typing "kit AutoPager" will provide ShellKit with output buffered through /usr/bin/more or your prefered pager program.
| Term-ShellKit documentation | Contained in the Term-ShellKit distribution. |
package Term::ShellKit::Commands; require Term::ShellKit; ###################################################################### sub eval ($) { my $input = shift; my @results = eval "package $Term::ShellKit::CurrentPackage; no strict qw( refs vars subs ); $input"; die $@ if $@; ! scalar( @results ) ? '' : scalar( @results == 1 ) ? ( ( ! defined $results[0] ) ? 'undef' : "$results[0]" ) : join(', ', map { ( ! defined ) ? 'undef' : ( ref $_ ) ? "$_" : "'$_'" } @results ); } sub package ($) { my $input = shift; $input =~ s/\;\s*$//; $Term::ShellKit::CurrentPackage = $input; } sub exit { exit; } sub kit { die "No kit name provided" unless ( scalar @_ ); map { Term::ShellKit::load_kit( $_ ) } @_; } ###################################################################### sub execute ($) { my $command = shift; qx{$command}; } ###################################################################### sub echo (;$) { shift; } ###################################################################### use vars qw( $PODViewer ); $PODViewer ||= "Pod::Text" || "Pod::Text::TermCap"; sub help (;$) { my $topic = shift || 'Term::ShellKit::Commands'; $topic =~ s/kit /Term::ShellKit::/; if ( $topic =~ /^[\w\:]+$/ ) { (my $lib = $topic . '.pm' ) =~ s|::|/|go; if ( ! $::INC{$lib} ) { eval { local $SIG{__DIE__}; require $lib } } $topic = $::INC{$lib} if ( $::INC{$lib} ); } Term::ShellKit::require_package( $PODViewer ); $PODViewer->new()->parse_from_file( $topic ); return; } ###################################################################### use vars qw( %CommandAliases ); %CommandAliases = ( '"' => 'echo', '$' => 'eval', '!' => 'execute', 'q' => 'exit', 'quit' => 'exit', '?' => 'help', ); sub alias { if ( scalar @_ ) { my $cmd = shift; if ( scalar @_ ) { $CommandAliases{ $cmd } = join ' ', @_; return; } else { $CommandAliases{ $cmd }; } } else { map "$_: $CommandAliases{ $_ }", sort keys %CommandAliases; } } sub _shell_rewrite { my $input = shift; $input =~ s/\A\s+//; my ($command, $args) = split(' ', $input, 2); my $alias = $CommandAliases{ $command } or return; return $alias . ( length($args) ? " $args" : '' ); } ###################################################################### 1; __END__