1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | #:META:X_RESOURCE:%.cmd:string:the command to run create a new pastebin |
3 | #:META:RESOURCE:%.cmd:string:the command to run create a new pastebin |
4 | #:META:X_RESOURCE:%.url:string:the url template for new pastebins |
4 | #:META:RESOURCE:%.url:string:the url template for new pastebins |
|
|
5 | |
|
|
6 | =head1 NAME |
|
|
7 | |
|
|
8 | selection-pastebin - automatic pastebin upload |
|
|
9 | |
|
|
10 | =head1 EXAMPLES |
|
|
11 | |
|
|
12 | URxvt.keysym.C-M-e: selection-pastebin:remote-pastebin |
|
|
13 | |
|
|
14 | =head1 DESCRIPTION |
|
|
15 | |
|
|
16 | This is a little rarely useful extension that uploads the selection as |
|
|
17 | textfile to a remote site (or does other things). (The implementation is |
|
|
18 | not currently secure for use in a multiuser environment as it writes to |
|
|
19 | F</tmp> directly.). |
|
|
20 | |
|
|
21 | It listens to the C<selection-pastebin:remote-pastebin> action, which, |
|
|
22 | when activated, runs a command with C<%> replaced by the name of the |
|
|
23 | textfile. This command can be set via a resource: |
|
|
24 | |
|
|
25 | URxvt.selection-pastebin.cmd: rsync -apP % ruth:/var/www/www.ta-sa.org/files/txt/. |
|
|
26 | |
|
|
27 | And the default is likely not useful to anybody but the few people around |
|
|
28 | here :) |
|
|
29 | |
|
|
30 | The name of the textfile is the hex encoded md5 sum of the selection, so |
|
|
31 | the same content should lead to the same filename. |
|
|
32 | |
|
|
33 | After a successful upload the selection will be replaced by the text given |
|
|
34 | in the C<selection-pastebin-url> resource (again, the % is the placeholder |
|
|
35 | for the filename): |
|
|
36 | |
|
|
37 | URxvt.selection-pastebin.url: http://www.ta-sa.org/files/txt/% |
|
|
38 | |
|
|
39 | I<Note to xrdb users:> xrdb uses the C preprocessor, which might interpret |
|
|
40 | the double C</> characters as comment start. Use C<\057\057> instead, |
|
|
41 | which works regardless of whether xrdb is used to parse the resource file |
|
|
42 | or not. |
|
|
43 | |
|
|
44 | =cut |
5 | |
45 | |
6 | sub upload_paste { |
46 | sub upload_paste { |
7 | my ($self) = @_; |
47 | my ($self) = @_; |
8 | |
48 | |
9 | require Digest::MD5; |
49 | require Digest::MD5; |
… | |
… | |
73 | }; |
113 | }; |
74 | |
114 | |
75 | () |
115 | () |
76 | } |
116 | } |
77 | |
117 | |
78 | sub on_user_command { |
118 | sub on_action { |
79 | my ($self, $cmd) = @_; |
119 | my ($self, $action) = @_; |
80 | |
120 | |
81 | if ($cmd eq "selection-pastebin:remote-pastebin") { |
121 | $action eq "remote-pastebin" |
82 | $self->upload_paste; |
122 | and $self->upload_paste; |
83 | } |
|
|
84 | |
123 | |
85 | () |
124 | () |
86 | } |
125 | } |
87 | |
126 | |