You are not logged in.
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 Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
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
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 Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
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
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
Last edited by Xyne (2008-12-06 00:41:48)
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline