rc file support.
This commit is contained in:
parent
491a7b1eca
commit
d6d085ee6f
1 changed files with 15 additions and 0 deletions
15
pshell.pl
15
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue