summaryrefslogtreecommitdiffstats
path: root/bin/nopaste
blob: 573af2e569f7189ee15d4f217889bd4d7e3dd3ed (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
#!/usr/bin/env perl
use strict;
use warnings;
use 5.020;

use Carp;
use File::Spec;
use File::Temp;
use POSIX 'strftime';

if (@ARGV > 1) {
    croak "can only nopaste one file at a time";
}

my $date = strftime("%Y-%m-%d", localtime);
my $template = "${date}-XXXXXXXX";
my $suffix = @ARGV
    ? "-${\(File::Spec->splitdir($ARGV[0]))[-1]}"
    : undef;

my $contents = do { local $/; <> };

my $tmpfile = File::Temp->new(
    TEMPLATE => $template,
    SUFFIX => $suffix,
    UNLINK => 1,
    TMPDIR => 1,
);
my $tmpfilename = $tmpfile->filename;

print $tmpfile $contents or croak "Can't write to $tmpfilename: $!";
close $tmpfile or croak "Can't write to $tmpfilename: $!";
chmod 0644 => $tmpfilename;

system('scp', '-pq', $tmpfilename, "tozt.net:paste");

say "https://paste.tozt.net/${\(File::Spec->splitdir($tmpfilename))[-1]}";