diff --git a/Makefile.PL b/Makefile.PL index a838921..2ab0438 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -7,5 +7,6 @@ WriteMakefile( 'DBI' => 0, 'DBD::SQLite' => 0, 'Term::ReadLine' => 0, + 'Cwd' => 0, }, ); diff --git a/lib/pshell_history.db b/lib/pshell_history.db new file mode 100644 index 0000000..e69de29 diff --git a/pshell.pl b/pshell.pl index 61c61fd..8d91546 100755 --- a/pshell.pl +++ b/pshell.pl @@ -3,6 +3,7 @@ use lib 'lib'; use History::SQLite; use Term::ReadLine; +use Cwd; # Initialize command history my $history = History::SQLite->new( @@ -19,7 +20,8 @@ my @history = $history->get_all; $term->addhistory($_) for @history; while (1) { - my $prompt = "pshell> "; + my $cwd = getcwd(); + my $prompt = "pshell:$cwd> "; my $command = $term->readline($prompt); last unless defined $command; @@ -29,6 +31,13 @@ while (1) { # 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; + } + # Save command to history $history->add($command); $term->addhistory($command); diff --git a/pshell_history.db b/pshell_history.db index a24003c..de1059c 100644 Binary files a/pshell_history.db and b/pshell_history.db differ