save point
This commit is contained in:
parent
1e414f35c9
commit
36b840f0da
4 changed files with 11 additions and 1 deletions
|
@ -7,5 +7,6 @@ WriteMakefile(
|
|||
'DBI' => 0,
|
||||
'DBD::SQLite' => 0,
|
||||
'Term::ReadLine' => 0,
|
||||
'Cwd' => 0,
|
||||
},
|
||||
);
|
||||
|
|
0
lib/pshell_history.db
Normal file
0
lib/pshell_history.db
Normal file
11
pshell.pl
11
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);
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue