rc file support.

This commit is contained in:
kake26 2025-04-14 11:49:22 -05:00
parent 491a7b1eca
commit d6d085ee6f
Signed by: kake26
GPG key ID: E0A989B571D1F99F

View file

@ -5,6 +5,7 @@ use History::SQLite;
use Environment::SQLite; use Environment::SQLite;
use Term::ReadLine; use Term::ReadLine;
use Cwd; use Cwd;
use File::HomeDir;
# Initialize command history and environment # Initialize command history and environment
my $history = History::SQLite->new( my $history = History::SQLite->new(
@ -27,6 +28,18 @@ $term->addhistory($_) for @history;
my %env_vars = $env->get_all; my %env_vars = $env->get_all;
$ENV{$_} = $env_vars{$_} for keys %env_vars; $ENV{$_} = $env_vars{$_} for keys %env_vars;
# Load and execute .pshellrc if it exists
my $rc_file = File::HomeDir->my_home . '/.pshellrc';
if (-e $rc_file && -r $rc_file) {
open my $fh, '<', $rc_file or warn "Could not open $rc_file: $!";
while (my $line = <$fh>) {
chomp $line;
next unless length $line;
system($line);
}
close $fh;
}
while (1) { while (1) {
my $cwd = getcwd(); my $cwd = getcwd();
my $prompt = "pshell:$cwd> "; my $prompt = "pshell:$cwd> ";
@ -59,6 +72,8 @@ while (1) {
next; next;
} }
# I guess we can insert more custom commands here
# Save command to history # Save command to history
$history->add($command); $history->add($command);
$term->addhistory($command); $term->addhistory($command);