This page looks best with JavaScript enabled

Urxvt tips I

 ·  🎃 kr0m

Urxvt is a highly configurable terminal emulator that allows for a wide range of configurations. It also has support for Perl scripts, making the possibilities limitless.

How many times have we found ourselves in the situation where we select text from a terminal and want to paste it into a web browser, but to paste it in the correct place, we have to first select the text to delete it, thus losing the original text?

It will be better understood with some screenshots. Here we can see how I select the text on the left in the console that I want to paste into Google:

In this other one, we had to select the text that was in the Google search to be able to paste the text from the console, thus losing the console selection:

To solve this, we will use a small tool called xclip, with which we can manage both the selection buffer (used by the middle button) and the other (Ctrl+V):

pkg install xclip
emerge -av x11-misc/xclip

Now a little magic in Urxvt, depending on the operating system we use, the path to the Urxvt extensions will be in one place or another:

/usr/local/lib/urxvt/perl/kr0m
/usr/lib64/urxvt/perl/kr0m

vi /usr/lib64/urxvt/perl/kr0m
#! perl
sub on_sel_grab {
        my $query = $_[0]->selection;
        open (my $pipe,'| /usr/bin/xclip -in -selection clipboard') or die;
        open (my $pipe2,'| /usr/bin/xclip -in') or die;
        print $pipe $query;
        print $pipe2 $query;
        close $pipe;
        close $pipe2;
}

We load the perl module:

vi .Xresources

URxvt.perl-ext-common: default,kr0m

Reload the config:

xrdb -load .Xresources

And that’s it, now when we select and paste in the browser, we will lose the text as before, but with Ctrl+V we can access the buffer we are interested in.

If you liked the article, you can treat me to a RedBull here