April 21, 2010 Archives

Wed 21 Apr 2010 @ 12:18 (1271848683)

urxvt selection2browser

Sometimes I need to open a few links from the terminal which are just words, so it's almost impossible to have them recognized by urxvt url matcher. This is why I've done this small script which allows you to open into your browser a piece of text previously selected on the terminal.

I'm far from being an urxvt expert so if you have better solutions please write me!

#! perl

sub on_start {
   my ($self) = @_;

   $self->{browser} = $self->x_resource ("urlLauncher") || "sensible-browser";

   ()
}

sub on_user_command {
   my ($self, $cmd) = @_;

   $cmd eq "selection2browser"
      and $self->exec_async ($self->{browser}, $self->selection);

   ()
}

I have this script saved as a file named selection2browser in my ~/.urxvt/perl/ directory and in order to activate it via Ctrl-Alt-w I put the following lines in ~/.Xresources:

URxvt.perl-lib: /home/shammash/.urxvt/perl/
URxvt.perl-ext-common: default,[other stuff],selection2browser
URxvt.keysym.C-M-w: perl:selection2browser

Posted by shammash | Permanent Link | Categories: tech