1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
|
|
sub on_start { |
4 |
|
|
my ($self) = @_; |
5 |
|
|
|
6 |
|
|
$self->grab_button (3, urxvt::ControlMask); |
7 |
|
|
} |
8 |
|
|
|
9 |
|
|
sub on_button_press { |
10 |
|
|
my ($self, $event) = @_; |
11 |
|
|
|
12 |
|
|
if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) { |
13 |
|
|
my $popup = $self->popup ($event) |
14 |
|
|
or return 1; |
15 |
|
|
|
16 |
|
|
$popup->add_title ("Convert Selection"); |
17 |
|
|
|
18 |
|
|
my $text = $self->selection; |
19 |
|
|
|
20 |
|
|
my $title = $text; |
21 |
|
|
$title =~ s/[\x00-\x1f\x80-\x9f]/ยท/g; |
22 |
|
|
substr $title, 40, -1, "..." if 40 < length $title; |
23 |
|
|
$popup->add_title ($title); |
24 |
|
|
$popup->add_separator; |
25 |
|
|
|
26 |
|
|
my $add_button = sub { |
27 |
|
|
my ($title, $cb) = @_; |
28 |
|
|
|
29 |
|
|
$popup->add_button ($title => sub { |
30 |
|
|
for ($text) { |
31 |
|
|
$cb->(); |
32 |
|
|
$self->selection ($_); |
33 |
|
|
} |
34 |
|
|
}); |
35 |
|
|
}; |
36 |
|
|
|
37 |
|
|
for ($text) { |
38 |
|
|
/^(\S+):(\d+):?$/ |
39 |
|
|
and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ }); |
40 |
|
|
/%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/ |
41 |
|
|
and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge }); |
42 |
|
|
/^(http|ftp|telnet|irc|news):\// |
43 |
|
|
and $add_button->("run x-www-browser" => sub { system "x-www-browser \Q$_\E &" }); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
$popup->show; |
47 |
|
|
|
48 |
|
|
return 1; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
() |
52 |
|
|
} |
53 |
|
|
|