NAME

Term::Shell::Enhanced - More functionality for Term::Shell

SYNOPSIS

use Term::Shell::Enhanced;
my $shell = Term::Shell::Enhanced->new;
$shell->print_greeting;
$shell->cmdloop;

DESCRIPTION

This class subclasses Term::Shell and adds some functionality.

FEATURES

The following features are added:

history

When the shell starts up, it tries to read the command history from the history file. Before quitting, it writes the command history to the history file - it does not append to it, it overwrites the file.

The default history file name is the shell name - with non-word characters replaced by underscores -, followed by _history, as a dotfile in $ENV{HOME}. For example, if you shell's name is mysh, the default history file name will be ~/.mysh_history.

You can override the history file name in the DEFAULTS(), like this:

use constant DEFAULTS => (
    history_filename => ...,
    ...
);
alias replacement

See the alias command below.

prompt strings

When subclassing Term::Shell::Enhanced, you can define how you want your prompt to look like. Use DEFAULTS() to override this.

use constant DEFAULTS => (
    prompt_spec => ...,
    ...
);

You can use the following prompt variables:

h    the hostname
n    the shell name
'#'  the command number (increased after each command)
\\   a literal backslash

You can extend the list of available prompt variables by defining your own PROMPT_VARS() - they are cumulative over the class hierarchy.

use constant PROMPT_VARS => (
    key => value,
    ...
);

Since more elaborate prompt variables will have some interaction with the shell object, you might need a more elaborate PROMPT_VARS() definition:

sub PROMPT_VARS {
    my $self = shift;
    (
        key => $self->some_method,
        ...
    );
}

The prompt variables are interpolated anew for every prompt.

The default prompt string is:

': \n:\#; ',

so if your shell is called mysh, the default prompt looks somewhat like this:

: mysh:1; 

COMMANDS

The following commands are added:

eval

You can evaluate snippets of Perl code just by putting them on a line beginning with !:

psh:~> ! print "$_\n" for keys %ENV
set [name[=value] ... ]

set lets you manipulate environment variables. You can view environment variables using set. To view specific variables, use set name. To set environment variables, use set foo=bar.

cd [dir]
cd foo/bar/baz

Change the current directory to the given directory. If no directory is given, the current value of $HOME is used.

pwd

Prints the current working directory.

alias [ name[=value] ... ]

alias with no arguments prints the list of aliases in the form NAME=VALUE on standard output. An alias is defined for each NAME whose VALUE is given.

When you enter any command, it is checked against aliases and replaced if there is an alias defined for it. Only the command name - that is, the first word of the input line - undergoes alias replacement.

echo [arg ...]

Output the args.

quit

Exits the program.

apropos <word>

Like the help command, but limits the information to commands that contain the given word in the command name or the summary.

METHODS

clear_opt
$obj->clear_opt;

Deletes all keys and values from the hash.

delete_opt
$obj->delete_opt(@keys);

Takes a list of keys and deletes those keys from the hash.

exists_opt
if ($obj->exists_opt($key)) { ... }

Takes a key and returns a true value if the key exists in the hash, and a false value otherwise.

keys_opt
my @keys = $obj->keys_opt;

Returns a list of all hash keys in no particular order.

opt
my %hash     = $obj->opt;
my $hash_ref = $obj->opt;
my $value    = $obj->opt($key);
my @values   = $obj->opt([ qw(foo bar) ]);
$obj->opt(%other_hash);
$obj->opt(foo => 23, bar => 42);

Get or set the hash values. If called without arguments, it returns the hash in list context, or a reference to the hash in scalar context. If called with a list of key/value pairs, it sets each key to its corresponding value, then returns the hash as described before.

If called with exactly one key, it returns the corresponding value.

If called with exactly one array reference, it returns an array whose elements are the values corresponding to the keys in the argument array, in the same order. The resulting list is returned as an array in list context, or a reference to the array in scalar context.

If called with exactly one hash reference, it updates the hash with the given key/value pairs, then returns the hash in list context, or a reference to the hash in scalar context.

opt_clear
$obj->opt_clear;

Deletes all keys and values from the hash.

opt_delete
$obj->opt_delete(@keys);

Takes a list of keys and deletes those keys from the hash.

opt_exists
if ($obj->opt_exists($key)) { ... }

Takes a key and returns a true value if the key exists in the hash, and a false value otherwise.

opt_keys
my @keys = $obj->opt_keys;

Returns a list of all hash keys in no particular order.

opt_values
my @values = $obj->opt_values;

Returns a list of all hash values in no particular order.

values_opt
my @values = $obj->values_opt;

Returns a list of all hash values in no particular order.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests through the web interface at http://rt.cpan.org.

INSTALLATION

See perlmodinstall for information and options on installing Perl modules.

AVAILABILITY

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN site near you. Or see http://search.cpan.org/dist/Term-Shell-Enhanced/.

AUTHORS

Marcel Grünauer, <marcel@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2005-2009 by the authors.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.