From 84640f1b3b402d2a64a5005d757f7171df2d658d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 31 May 2013 04:51:29 -0500 Subject: add some configuration to a couple plugins --- lib/Reply/Plugin/ReadLine.pm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'lib/Reply/Plugin/ReadLine.pm') diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm index 29ad5a0..54c262b 100644 --- a/lib/Reply/Plugin/ReadLine.pm +++ b/lib/Reply/Plugin/ReadLine.pm @@ -8,15 +8,26 @@ 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 %opts = @_; my $self = $class->SUPER::new(@_); $self->{term} = Term::ReadLine->new('Reply'); + my $history = $opts{history_file} || '.reply_history'; + $self->{history_file} = File::Spec->catfile( + (File::Spec->file_name_is_absolute($history) + ? () + : (File::HomeDir->my_data)), + $history + ); + + if ($self->{term}->ReadLine eq 'Term::ReadLine::Gnu') { + $self->{term}->StifleHistory($opts{history_length}) + if defined $opts{history_length} && $opts{history_length} >= 0; + } - if (open my $fh, '<', $history) { + if (open my $fh, '<', $self->{history_file}) { for my $line (<$fh>) { chomp $line; $self->{term}->addhistory($line); @@ -24,8 +35,8 @@ sub new { } else { my $e = $!; - warn "Couldn't open $history for reading: $e" - if -e $history; + warn "Couldn't open $self->{history_file} for reading: $e" + if -e $self->{history_file}; } return $self; @@ -44,8 +55,8 @@ sub DESTROY { # 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"; + $self->{term}->WriteHistory($self->{history_file}) + or warn "Couldn't write history to $self->{history_file}"; } 1; -- cgit v1.2.3-54-g00ecf