1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | #:META:X_RESOURCE:url-launcher:string:shell command to use |
2 | |
4 | |
3 | sub msg { |
5 | sub msg { |
4 | my ($self, $msg) = @_; |
6 | my ($self, $msg) = @_; |
5 | |
7 | |
6 | my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1); |
8 | my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1); |
… | |
… | |
12 | } |
14 | } |
13 | |
15 | |
14 | sub on_start { |
16 | sub on_start { |
15 | my ($self) = @_; |
17 | my ($self) = @_; |
16 | |
18 | |
17 | $self->{browser} = $self->x_resource ("urlLauncher") || "x-www-browser"; |
19 | $self->{browser} = $self->x_resource ("url-launcher") || "sensible-browser"; |
18 | |
20 | |
19 | $self->grab_button (3, urxvt::ControlMask); |
21 | $self->grab_button (3, urxvt::ControlMask); |
20 | |
22 | |
21 | () |
23 | () |
22 | } |
24 | } |
… | |
… | |
54 | } |
56 | } |
55 | }); |
57 | }); |
56 | }; |
58 | }; |
57 | |
59 | |
58 | for ($text) { |
60 | for ($text) { |
|
|
61 | /\n/ |
|
|
62 | and $add_button->("newlines to spaces" => sub { y/\n/ / }); |
|
|
63 | |
59 | /./ |
64 | /./ |
60 | and $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); |
65 | and $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); |
61 | |
66 | |
62 | /./ |
67 | /./ |
63 | and $add_button->("eval perl expression" => sub { no warnings; $_ = eval $_ }); |
68 | and $add_button->("eval perl expression" => sub { my $self = $self; no warnings; $_ = eval $_; $_ = "$@" if $@ }); |
64 | |
69 | |
|
|
70 | /./ |
|
|
71 | and $add_button->((sprintf "to unicode hex index (%x)", ord) => sub { $_ = sprintf "%x", ord }); |
|
|
72 | |
65 | /^(\S+):(\d+):?$/ |
73 | /(\S+):(\d+):?/ |
66 | and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ }); |
74 | and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ }); |
67 | |
75 | |
68 | /%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/ |
76 | /%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/ |
69 | and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge }); |
77 | and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge }); |
70 | |
78 | |
71 | /[\\"'\ \t|&;<>()]/ |
79 | /[\\"'\ \t|&;<>()]/ |
72 | and $add_button->("shell quote" => sub { $_ = "\Q$_" }); |
80 | and $add_button->("shell quote" => sub { $_ = "\Q$_" }); |
73 | |
81 | |
74 | /^(http|ftp|telnet|irc|news):\// |
82 | /^(https?|ftp|telnet|irc|news):\// |
75 | and $add_button->("run $self->{browser}" => sub { $self->exec_async ($self->{browser}, $_) }); |
83 | and $add_button->("run $self->{browser}" => sub { $self->exec_async ($self->{browser}, $_) }); |
76 | |
84 | |
77 | warn "hook for $self $self->{term}\n";#d# |
|
|
78 | for my $hook (@{ $self->{term}{selection_popup_hook} || [] }) { |
85 | for my $hook (@{ $self->{term}{selection_popup_hook} || [] }) { |
79 | if (my ($title, $cb) = $hook->($popup)) { |
86 | if (my ($title, $cb) = $hook->($popup)) { |
80 | $add_button->($title, $cb); |
87 | $add_button->($title, $cb); |
81 | } |
88 | } |
82 | } |
89 | } |