From b9ed547db043ef57dca6d2d633c344bf0a00af2c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 30 May 2013 05:20:24 -0500 Subject: save readline history --- lib/Reply/Plugin/ReadLine.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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; -- cgit v1.2.3-54-g00ecf