You are not logged in.

#26 2008-12-05 20:29:19

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Hacking urxvt scripts -- Perl help needed [FINISHED]

That's happening because the substitution is re-inserting the actual newline character preceded by a backslash (same thing for the carriage-return character), e.g. this

some text
with a line break

would be converted to

some text\
with a line break

.

Perhaps you could clean that up a bit using quotemeta, something like this:

sub on_sel_grab {
    my $query = quotemeta $_[0]->selection;
    $query =~ s/\n/n/g;
    $query =~ s/\r/r/g;
    system( "echo -en " . $query . " | xsel -ibp" );
}

I haven't tested this though.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#27 2008-12-05 22:20:57

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Hacking urxvt scripts -- Perl help needed [FINISHED]

Perfect explanation Xyne.

Your code needs a minor adjustment:

#! /usr/bin/perl

sub on_sel_grab {
    my $query = quotemeta $_[0]->selection;
    $query =~ s/\n/\\n/g;
    $query =~ s/\r/\\r/g;
    system( "echo -en " . $query . " | xsel -ibp" );
}

That looks so much cleaner. Thanks.

--EDIT--

I forgot to mention to anyone that may find this code useful. The selection is being copied to both the primary selection and the clipboard. This was necessary because urxvt's selection code traps the selection before it makes it to the X buffer.

Last edited by skottish (2008-12-05 22:25:24)

Offline

#28 2008-12-05 23:20:29

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Hacking urxvt scripts -- Perl help needed [FINISHED]

That's strange. The quotemeta should have inserted the backslashes before the newlines and carriage returns, e.g.

Here's another example
with a line break.

->quotemeta->

Here\'s another example\
with a line break\.

-> s/\n/n/g ->

Here\'s another example\nwith a line break\.

That's how it works here anyway.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#29 2008-12-05 23:33:21

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Hacking urxvt scripts -- Perl help needed [FINISHED]

I had similar problems with echo while doing this. That's how I ended up with the second regex line. By all accounts it seemed like the code should have worked, but alas, there needed to be something different.

Offline

#30 2008-12-06 00:35:23

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Hacking urxvt scripts -- Perl help needed [FINISHED]

It must be running through 2 interpolations. I haven't read through all the posts in this thread though, so I"m not sure what or where.

*edit*
nor does it matter, as long as it works wink

Last edited by Xyne (2008-12-06 00:41:48)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB