From d6d085ee6f3e6d9e392fbc26297dd86b84a9f64d Mon Sep 17 00:00:00 2001 From: kake26 Date: Mon, 14 Apr 2025 11:49:22 -0500 Subject: [PATCH] rc file support. --- pshell.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pshell.pl b/pshell.pl index d126c38..c973a0e 100755 --- a/pshell.pl +++ b/pshell.pl @@ -5,6 +5,7 @@ use History::SQLite; use Environment::SQLite; use Term::ReadLine; use Cwd; +use File::HomeDir; # Initialize command history and environment my $history = History::SQLite->new( @@ -27,6 +28,18 @@ $term->addhistory($_) for @history; my %env_vars = $env->get_all; $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) { my $cwd = getcwd(); my $prompt = "pshell:$cwd> "; @@ -58,6 +71,8 @@ while (1) { print "$_=$ENV{$_}\n" for sort keys %ENV; next; } + + # I guess we can insert more custom commands here # Save command to history $history->add($command);