diff options
-rw-r--r-- | lib/Reply/Plugin/ReadLine.pm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm index dc9c617..29ad5a0 100644 --- a/lib/Reply/Plugin/ReadLine.pm +++ b/lib/Reply/Plugin/ReadLine.pm @@ -4,14 +4,30 @@ use warnings; use base 'Reply::Plugin'; +use File::HomeDir; +use File::Spec; use Term::ReadLine; +my $history = File::Spec->catfile(File::HomeDir->my_data, '.reply_history'); + sub new { my $class = shift; my $self = $class->SUPER::new(@_); $self->{term} = Term::ReadLine->new('Reply'); + if (open my $fh, '<', $history) { + for my $line (<$fh>) { + chomp $line; + $self->{term}->addhistory($line); + } + } + else { + my $e = $!; + warn "Couldn't open $history for reading: $e" + if -e $history; + } + return $self; } @@ -22,4 +38,14 @@ sub read_line { return $self->{term}->readline($prompt); } +sub DESTROY { + my $self = shift; + + # XXX support more later + return unless $self->{term}->ReadLine eq 'Term::ReadLine::Gnu'; + + $self->{term}->WriteHistory($history) + or warn "Couldn't write history to $history"; +} + 1; |