1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | #:META:X_RESOURCE:%.cmd:string:the command to run create a new pastebin |
|
|
4 | #:META:X_RESOURCE:%.url:string:the url template for new pastebins |
2 | |
5 | |
3 | sub upload_paste { |
6 | sub upload_paste { |
4 | my ($self) = @_; |
7 | my ($self) = @_; |
5 | |
8 | |
6 | require Digest::MD5; |
9 | require Digest::MD5; |
7 | |
10 | |
8 | my $txt = $self->selection; |
11 | my $txt = $self->selection; |
|
|
12 | |
|
|
13 | my $filename = $txt; |
|
|
14 | utf8::encode $filename; |
9 | my $filename = Digest::MD5::md5_hex ($txt) . ".txt"; |
15 | $filename = Digest::MD5::md5_hex ($filename) . ".txt"; |
10 | |
16 | |
11 | my $tmpfile = "/tmp/$filename"; |
17 | my $tmpfile = "/tmp/$filename"; |
12 | |
18 | |
13 | my $msg = "uploaded as $filename"; |
19 | my $msg = "uploaded as $filename"; |
14 | |
20 | |
… | |
… | |
21 | } |
27 | } |
22 | |
28 | |
23 | my $cmd = $self->{pastebin_cmd}; |
29 | my $cmd = $self->{pastebin_cmd}; |
24 | $cmd =~ s/%/$tmpfile/; |
30 | $cmd =~ s/%/$tmpfile/; |
25 | |
31 | |
26 | my $pid = $self->exec_async ("/bin/sh", "-c", $cmd); |
32 | my $pid = $self->exec_async ($cmd); |
27 | |
33 | |
28 | $self->{pw} = urxvt::pw->new->start ($pid)->cb (sub { |
34 | $self->{pw} = urxvt::pw->new->start ($pid)->cb (sub { |
29 | my (undef, $status) = @_; |
35 | my (undef, $status) = @_; |
30 | |
36 | |
31 | delete $self->{pw}; |
37 | delete $self->{pw}; |
… | |
… | |
67 | }; |
73 | }; |
68 | |
74 | |
69 | () |
75 | () |
70 | } |
76 | } |
71 | |
77 | |
72 | sub on_keyboard_command { |
78 | sub on_user_command { |
73 | my ($self, $cmd) = @_; |
79 | my ($self, $cmd) = @_; |
74 | |
80 | |
75 | if ($cmd eq "selection-pastebin:remote-pastebin") { |
81 | if ($cmd eq "selection-pastebin:remote-pastebin") { |
76 | $self->upload_paste; |
82 | $self->upload_paste; |
77 | } |
83 | } |