
use Zoidberg::Shell qw/:all/;
use Zoidberg::Utils qw/:output/;

### welcome message
message(
"--[ This is the Zoidberg shell ]--[ Version $Zoidberg::VERSION ]--
### This is a development version, consider it unstable" );

# FIXME set exit message
$shell = Zoidberg::Shell->new(); # get object
$shell->{events}{exit} = sub { message("--[ CU ]--[ Please report all bugs ]--") };

### set environment
%env = (
	EDITOR	=> 'vim',
	MAILER	=> '',
	PAGER	=> 'less',
	BROWSER	=> 'lynx',
#	PS1	=> '[\u@\h(\L) \W]',
);

# some glue for the Gentoo distrobution
if (-e '/etc/profile.env') {
	open EXP, '/etc/profile.env';
	while (<EXP>) {
		next unless /^\s*export\s*(\w+)=['"](.*?)['"]/;
		$env{$1} = $2;
	}
	close EXP;
}

# do not overwrite existing values
$ENV{$_} ||= $env{$_} for keys %env;

# Some programs expect this var to point to a fully posix compliant shell.
# Since zoid doesn't use this var, no harm is done.
# Notice that even perl core utils like perldoc have expectations about it.
$ENV{SHELL} = '/bin/sh';

### set aliases
alias( {
	export   => 'setenv', # setenv provided by Commands plugin
	ls       => 'ls --color=auto',
	ll       => 'ls --color=auto -l',
	up       => 'cd ..',
	bye      => 'exit',
	( ($> == 0) # root gets other aliases
		? ( perldoc => 'perldoc -U', perlfunc => 'perldoc -Uf' )
		: ( perlfunc => 'perldoc -f' )
	),
} );

### set default settings
# set( );

__END__

TODO for PS1

['[',{color=>'red'}],
['\u',{color=>'magenta'}],
['@',{color=>'blue'}],
['\h',{color=>'green'}],
['(\L)',{color=>'yellow',if=>'sub{my$s=$self->stringify;$s=~s{\e.*?m}{}g;if($s=~/\d/){return 1} else { return 0 }}'}],
' ',
['\W',{color=>'cyan'}],
[']',{color=>'red'}],
' ',
],

