diff options
author | trizen <trizen@protonmail.com> | 2020-06-15 15:40:34 +0300 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2020-06-15 15:40:34 +0300 |
commit | 48d5267401926628bfab8abc61b2247ec3dede23 (patch) | |
tree | d10693c8f45ec5073e705a2119628a1b2ef61ca2 /bin | |
parent | 71bc58c94d416d6660e562f642674fb603c1bfcc (diff) | |
download | fair-viewer-48d5267401926628bfab8abc61b2247ec3dede23.tar.lz fair-viewer-48d5267401926628bfab8abc61b2247ec3dede23.tar.xz fair-viewer-48d5267401926628bfab8abc61b2247ec3dede23.zip |
Handle some potential corner cases.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/fair-viewer | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/bin/fair-viewer b/bin/fair-viewer index 6e391ad..bb30e6a 100755 --- a/bin/fair-viewer +++ b/bin/fair-viewer @@ -397,7 +397,7 @@ EOD my $dumped_config = q{our $CONFIG = } . Data::Dump::pp(\%CONFIG) . "\n"; - if ($home_dir eq $ENV{HOME}) { + if (defined($ENV{HOME}) and $home_dir eq $ENV{HOME}) { $dumped_config =~ s/\Q$home_dir\E/\$ENV{HOME}/g; } @@ -513,7 +513,7 @@ sub load_config { # Enable history if Term::ReadLine::Gnu::XS is installed if (not defined $CONFIG{history}) { - if ($term->can('ReadHistory')) { + if (eval { $term->can('ReadHistory') }) { $CONFIG{history} = 1; } else { @@ -561,12 +561,24 @@ if ($opt{history}) { # Create the history file. if (not -e $opt{history_file}) { + + require File::Basename; + my $dir = File::Basename::dirname($opt{history_file}); + + if (not -d $dir) { + require File::Path; + File::Path::make_path($dir) + or warn "[!] Can't create path <<$dir>>: $!"; + } + open my $fh, '>', $opt{history_file} or warn "[!] Can't create the history file `$opt{history_file}': $!"; } # Add history to Term::ReadLine - $term->ReadHistory($opt{history_file}); + if (eval { $term->can('ReadHistory') }) { + $term->ReadHistory($opt{history_file}); + } # All history entries my @history = $term->history_list; |