save point working environment variables
This commit is contained in:
parent
3ddd822c15
commit
c835810c0e
4 changed files with 105 additions and 5 deletions
23
pshell.pl
23
pshell.pl
|
@ -2,13 +2,17 @@
|
|||
|
||||
use lib 'lib';
|
||||
use History::SQLite;
|
||||
use Environment::SQLite;
|
||||
use Term::ReadLine;
|
||||
use Cwd;
|
||||
|
||||
# Initialize command history
|
||||
# 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";
|
||||
|
||||
|
@ -19,6 +23,10 @@ $term->ornaments(0);
|
|||
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> ";
|
||||
|
@ -38,6 +46,19 @@ while (1) {
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue