summaryrefslogtreecommitdiffstats
path: root/bin/reply
blob: c4f284cfb01f98e52a2e4422038fd58db763289a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env perl
use strict;
use warnings;
# PODNAME: reply
# ABSTRACT: read, eval, print, loop, yay!

use File::HomeDir;
use File::Spec;
use Getopt::Long;

use Reply;

=head1 SYNOPSIS

  reply

=head1 DESCRIPTION

This script runs the L<Reply> shell. It looks for a configuration file in
C<.replyrc> in your home directory, and will generate a basic configuration for
you if that file does not exist.

See the L<Reply> documentation for more information about using and configuring
this program.

=cut

my $cfgfile = '.replyrc';
GetOptions(
    'cfg:s'   => \$cfgfile,
    'version' => sub { version() },
    'help'    => sub { usage(0) },
) or usage(1);

my $cfg = File::Spec->catfile(
    (File::Spec->file_name_is_absolute($cfgfile)
        ? ()
        : (File::HomeDir->my_home)),
    $cfgfile
);

my %args = (config => $cfg);
if (!-e $cfg) {
    print("$cfg not found. Generating a default...\n");
    if (open my $fh, '>', $cfg) {
        my $contents = do {
            local $/;
            <DATA>
        };
        $contents =~ s/use 5.XXX/use $]/;
        print $fh $contents;
        close $fh;
    }
    else {
        warn "Couldn't write to $cfg";
        %args = ();
    }
}

Reply->new(%args)->run;

sub usage {
    print "    reply [--version] [--help] [--cfg file]\n";
    exit($_[0]);
}

sub version {
    print "Reply version $Reply::VERSION\n";
    exit(0);
}

__DATA__
script_line1 = use strict
script_line2 = use warnings
script_line3 = use 5.XXX

[Interrupt]
[FancyPrompt]
[DataDumper]
[Colors]
[ReadLine]
[Hints]
[Packages]
[LexicalPersistence]
[ResultCache]