68 lines
1.5 KiB
Perl
Executable file
68 lines
1.5 KiB
Perl
Executable file
#!/usr/bin/env perl
|
|
|
|
use lib 'lib';
|
|
use History::SQLite;
|
|
use Environment::SQLite;
|
|
use Term::ReadLine;
|
|
use Cwd;
|
|
|
|
# Initialize command history and environment
|
|
my $history = History::SQLite->new(
|
|
db_path => 'pshell_history.db'
|
|
);
|
|
my $env = Environment::SQLite->new(
|
|
db_path => 'pshell_env.db'
|
|
);
|
|
|
|
print "Perl Shell (pshell) - Type 'exit' to quit\n";
|
|
|
|
my $term = Term::ReadLine->new('pshell');
|
|
$term->ornaments(0);
|
|
|
|
# Load previous history
|
|
my @history = $history->get_all;
|
|
$term->addhistory($_) for @history;
|
|
|
|
# Load environment variables
|
|
my %env_vars = $env->get_all;
|
|
$ENV{$_} = $env_vars{$_} for keys %env_vars;
|
|
|
|
while (1) {
|
|
my $cwd = getcwd();
|
|
my $prompt = "pshell:$cwd> ";
|
|
my $command = $term->readline($prompt);
|
|
|
|
last unless defined $command;
|
|
chomp $command;
|
|
last if $command =~ /^exit$/i;
|
|
|
|
# Skip empty commands
|
|
next unless length $command;
|
|
|
|
# Handle cd command specially
|
|
if ($command =~ /^cd\s*(.*)/) {
|
|
my $dir = $1 || $ENV{HOME};
|
|
chdir $dir or warn "Could not change to directory $dir: $!";
|
|
next;
|
|
}
|
|
|
|
# Handle environment variable assignment
|
|
if ($command =~ /^export\s+(\w+)=(.*)/) {
|
|
$ENV{$1} = $2;
|
|
$env->set($1, $2);
|
|
next;
|
|
}
|
|
|
|
# Handle environment variable display
|
|
if ($command eq 'env') {
|
|
print "$_=$ENV{$_}\n" for sort keys %ENV;
|
|
next;
|
|
}
|
|
|
|
# Save command to history
|
|
$history->add($command);
|
|
$term->addhistory($command);
|
|
|
|
# Execute command
|
|
system($command);
|
|
}
|