summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-05-30 05:20:24 -0500
committerJesse Luehrs <doy@tozt.net>2013-05-30 05:20:24 -0500
commitb9ed547db043ef57dca6d2d633c344bf0a00af2c (patch)
tree503ffeeec07654de5cc7a2b8facbf149ace7a906
parentfb9b17bd52b48a7eea32585e0f743a887a61c7d7 (diff)
downloadreply-b9ed547db043ef57dca6d2d633c344bf0a00af2c.tar.gz
reply-b9ed547db043ef57dca6d2d633c344bf0a00af2c.zip
save readline history
-rw-r--r--lib/Reply/Plugin/ReadLine.pm26
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;