You are not logged in.

#1 2009-09-15 17:33:20

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Urxvt pasting from clipboard.. efficient, fast, clean

All urxvt users know this problem: you cannot paste from X clipboard into urxvt.

There are various workarounds.  Many of them rely on synchronizing primary selection with clipboard (which I do not like.  I don't want to "lose" a buffer).  this can be in the form of autocutsel, or keybinds to do something like "xsel -bo | xsel -p", which has the additional disadvantage it requires an extra keyboard shortcut (one to sync the primary selection, one to do the actual paste).

I was wondering what would be a simple and clean way to paste the clipboard into urxvt (by using a -but only one- keyboard shortcut), without touching the primary selection.

I came up with putting this in my .xbindkeysrc

"xdotool type "$(xsel -bo)""
 alt+Insert

But it's not perfect.  I also tried with --clearmodifiers.  If you try this out, you'll notice sometimes the paste will work, sometimes it will work half.  Sometimes it replaces existing text, sometimes it will do nothing, and the best part is sometimes if you do backspace or stuff like that it behaves differently, I actually messed up my keyboard events with this.

Anyone an idea for the "perfect" way to go?


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#2 2009-09-15 18:05:14

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Hmmm I think I may have fixed it

"xdotool type --delay 0 --clearmodifiers "$(xsel -bo)""
 alt+Insert

this works pretty well. sometimes nothing at all happens, but usually it types the contents of my clipboard, without screwing my keymap or entering weird stuff big_smile


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#3 2009-09-15 18:24:42

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

There was a post quite awhile ago that suggested adding the following perl script to /usr/lib/urxvt/perl/clipboard

#! 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" );
}

and then adding the following to .Xdefaults:

URxvt*perl-ext-common:      default,matcher,clipboard

I've been using that quite happily for some time, and am able to copy/paste both ways to/from urxvt/firefox. I don't remember who posted it.

Scott

Offline

#4 2009-09-15 18:47:23

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Also try this:
"xsel -x; xsel -o -b | xsel -i; xdotool click 2; xsel -x"

Offline

#5 2009-09-15 19:11:32

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

firecat53 wrote:

There was a post quite awhile ago that suggested adding the following perl script to /usr/lib/urxvt/perl/clipboard

#! 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" );
}

and then adding the following to .Xdefaults:

URxvt*perl-ext-common:      default,matcher,clipboard

I've been using that quite happily for some time, and am able to copy/paste both ways to/from urxvt/firefox. I don't remember who posted it.

Scott

do you know how this works? does it comply to my wishes? (don't override primary, allow pasting clipboard _into_ urxvt? this seems to be about going _from_ urxvt to something else)

Procyon wrote:

Also try this:
"xsel -x; xsel -o -b | xsel -i; xdotool click 2; xsel -x"

great! this seems to work just as well, if not better then my initial trick smile thank you!


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#6 2009-09-15 20:30:53

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Instead of xdotool click 2, for GUIs it is better to use xdotool key shift+Insert.

Offline

#7 2009-09-16 00:25:13

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

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Dieter@be wrote:

...snip...

do you know how this works? does it comply to my wishes? (don't override primary, allow pasting clipboard _into_ urxvt? this seems to be about going _from_ urxvt to something else)

You're correct in that it's only for going out of urxvt. And, it does in fact overwrite the primary selection too. Removing the 'p' switch will prevent that. But you should know that. You suffered through the whole thread with me!

Offline

#8 2009-09-16 06:12:51

ugkbunb
Member
Registered: 2009-02-26
Posts: 227

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Dieter@be wrote:

"xsel -x; xsel -o -b | xsel -i; xdotool click 2; xsel -x"

Sorry for my stupid question... but where do I insert this... into .xbindkeysrc ?

and how would one edit it to be active on alt+v?

Is this the correct usage?
"xsel -x; xsel -o -b | xsel -i; xdotool key alt+v; xsel -x"

herm I pasted it in my .xbindkeysrc *I didnt have that file and had to make it... rebooted and I am unable to get this to work... I do have xdotool installed as well as xbindkeys.

Also -- I have been just using the compiz bind plugin for my keybindings... how would I edit it to not use xdotool/xbindkeys?

I tried the following but it didnt seem to do anything when triggered:
"xsel -x; xsel -o -b | xsel -i; xsel -x"

Last edited by ugkbunb (2009-09-16 06:33:41)

Offline

#9 2009-09-16 12:17:36

LeoSolaris
Member
From: South Carolina
Registered: 2008-03-30
Posts: 354

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Wow...   I always used a middle click on the urxvt window to paste whatever was highlighted... I can even alter what I paste with parcellite if I want.

Come to think of it though urxvt is the only program I have found that has ever required the middle click, though it can be used elsewhere.

I just make sure to keep Use Copy and Use Primary (Selection) checked in parcellite's preferences. I wouldn't recommend checking Synchronize clipboards though, the results get a little weird for me.


I keep getting distracted from my webserver project...

huh? oooh...  shiny!

Offline

#10 2009-09-16 18:03:27

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Procyon wrote:

Instead of xdotool click 2, for GUIs it is better to use xdotool key shift+Insert.

why?

skottish wrote:
Dieter@be wrote:

...snip...

do you know how this works? does it comply to my wishes? (don't override primary, allow pasting clipboard _into_ urxvt? this seems to be about going _from_ urxvt to something else)

You're correct in that it's only for going out of urxvt. And, it does in fact overwrite the primary selection too. Removing the 'p' switch will prevent that. But you should know that. You suffered through the whole thread with me!

Well actually i don't even have a problem with going out of urxvt.  AFAIK all my apps support pasting from the primary buffer, so I'm good.


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#11 2009-09-16 18:46:58

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Urxvt pasting from clipboard.. efficient, fast, clean

@Dieter: Because if you use it as a C+V substitute you expect it to paste at the text cursor while middle click will paste at the mouse cursor (or not at all if the mouse is outside the text box).

Offline

#12 2009-09-16 19:17:56

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Procyon wrote:

@Dieter: Because if you use it as a C+V substitute you expect it to paste at the text cursor while middle click will paste at the mouse cursor (or not at all if the mouse is outside the text box).

okay thanks.  I also want to ask, why did you add the clause "for GUI tools.." ? is there a catch when using shift+insert? or is it better then middleclick in all aspects/use cases?


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#13 2009-09-16 20:18:29

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Urxvt pasting from clipboard.. efficient, fast, clean

With "GUI" I mean GTK and such (also ncurses, where you can also disable the mouse and it's location sensitive). One catch is that it won't work if the keyboard is grabbed, like with dmenu, only middle click will work. Otherwise it seems to be the same.

Offline

#14 2009-09-17 11:37:48

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Procyon wrote:

With "GUI" I mean GTK and such (also ncurses, where you can also disable the mouse and it's location sensitive). One catch is that it won't work if the keyboard is grabbed, like with dmenu, only middle click will work. Otherwise it seems to be the same.

ah well, i actually consider this a missing feature in dmenu. If dmenu is running, i want shift+insert to paste in dmenu.


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#15 2009-09-18 17:14:00

rine
Member
From: Germany
Registered: 2008-03-04
Posts: 217

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Haven't read everything here, but I don't get the problem. What's wrong with just pasting with shift+insert?

Offline

#16 2009-09-18 18:50:36

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

rine wrote:

Haven't read everything here, but I don't get the problem. What's wrong with just pasting with shift+insert?

it only works for primary selection buffer. not clipboard.  E.g. in firefox when you click on a link/image/ you can do 'copy destination url', but not 'copy destination url to primary selection buffer'


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#17 2009-09-19 13:35:23

alterecco
Member
Registered: 2009-07-13
Posts: 152

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Strange - that example (copy destination url, paste with Shift-Insert) works fine by me. I can't say I don't have any problems with copy/paste in X, but mostly it works fine. Perhaps using vimperator in firefox solves some of the issues?

Offline

#18 2009-09-19 16:19:37

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

alterecco wrote:

Strange - that example (copy destination url, paste with Shift-Insert) works fine by me. I can't say I don't have any problems with copy/paste in X, but mostly it works fine. Perhaps using vimperator in firefox solves some of the issues?

If anything, I should be using uzbl more smile

but I don't get your explanation.  if you do "copy destination url" on a link it is in your clipboard. and AFAIK shift-insert = paste from primary selection, not from clipboard. at least that's how it is for me


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#19 2009-09-19 23:29:12

alterecco
Member
Registered: 2009-07-13
Posts: 152

Re: Urxvt pasting from clipboard.. efficient, fast, clean

Dieter@be wrote:

but I don't get your explanation.  if you do "copy destination url" on a link it is in your clipboard. and AFAIK shift-insert = paste from primary selection, not from clipboard. at least that's how it is for me

I'm afraid that is all there is to it, and that I can offer no explanation at the moment. When doing right click, copy link/image locations in both firefox (w. vimperator) or uzbl, i can paste it directly into urxvt with shift-insert. I am pretty sure that I have done no magic on my system to enable this feature, and I am positive I have no app running that facilitates this, but it might be an obscure side effect. I will try to hunt it down, given the time...

Offline

#20 2009-09-20 04:06:39

ugkbunb
Member
Registered: 2009-02-26
Posts: 227

Re: Urxvt pasting from clipboard.. efficient, fast, clean

^^
woh--- yah it works for me too.... just have to make sure you have the cursor in the windows boundaries

Offline

#21 2009-10-30 15:56:52

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Urxvt pasting from clipboard.. efficient, fast, clean

I used this in my .xinitrc

autocutsel -fork &
autocutsel -selection PRIMARY -fork &

I believe this adds the clipboard buffer contents to the primary buffer.

What I was wondering if anyone knows a way to append the contents of the primary buffer to a file as soon as something is added to the primary buffer?  Maybe using something xsel/xclip/sselp -o ?  I know one could run a 'while true loop' every second but I was wondering if anyone knew of a more elegant solution.

I was thinking it might be nice to bind mod4+p to shift+insert and bind mod4+shift+p to a vertical demu list of the paste file I mentioned above.

Offline

#22 2009-10-31 15:50:25

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Urxvt pasting from clipboard.. efficient, fast, clean

I just use Ratpoison, which can simulate clicks tongue
I have a binding (yep...one key) to simulate middle click.
I also have a binding that cycles frames on ALT+TAB, and while doing this it banishes the cursor to the lower right corner of the window, so it makes sure that I'm always on the selected frame when I paste. This also gets the nasty rat out of the way so double win for me big_smile

Last edited by Lich (2009-10-31 15:52:08)


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#23 2010-04-29 05:06:13

realturner
Member
Registered: 2010-04-29
Posts: 3

Re: Urxvt pasting from clipboard.. efficient, fast, clean

I've just found this page recently and made a solution:

#! perl -w

# Usage:
# URxvt.perl-ext-common: clipboard
# URxvt.keysym.Mod4-c: perl:clipboard:copy
# URxvt.keysym.Mod4-v: perl:clipboard:paste

# consult command "xmodmap" to see what your modifier mapped into.

sub copy {
   my ($self) = @_;
   my $pid = open( pout, "| xsel -ib" ) or die "fork";
   print pout $self->selection;
   close(pout) or die "close";
}

sub paste {
   my ($self) = @_;
   my $content = `xsel -ob` ;
   $self->tt_write ($content);
}

sub on_user_command {
   my ($self, $cmd) = @_;
   if ($cmd eq "clipboard:copy") {
      $self->copy;
   }
   if ($cmd eq "clipboard:paste") {
      $self->paste;
   }
}

save this script as /usr/lib/urxvt/perl/clipboard
then add lines in ~/.Xdefaults:

URxvt.perl-ext-common: clipboard
URxvt.keysym.Mod4-c: perl:clipboard:copy
URxvt.keysym.Mod4-v: perl:clipboard:paste

should have a good work for copy/paste via Win+C/V cool

Edit: changed the method piping to xsel, avoid escape sequence problem.

Last edited by realturner (2010-04-29 06:14:57)

Offline

#24 2010-05-09 08:47:09

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

realturner wrote:

I've just found this page recently and made a solution:

#! perl -w

# Usage:
# URxvt.perl-ext-common: clipboard
# URxvt.keysym.Mod4-c: perl:clipboard:copy
# URxvt.keysym.Mod4-v: perl:clipboard:paste

# consult command "xmodmap" to see what your modifier mapped into.

sub copy {
   my ($self) = @_;
   my $pid = open( pout, "| xsel -ib" ) or die "fork";
   print pout $self->selection;
   close(pout) or die "close";
}

sub paste {
   my ($self) = @_;
   my $content = `xsel -ob` ;
   $self->tt_write ($content);
}

sub on_user_command {
   my ($self, $cmd) = @_;
   if ($cmd eq "clipboard:copy") {
      $self->copy;
   }
   if ($cmd eq "clipboard:paste") {
      $self->paste;
   }
}

save this script as /usr/lib/urxvt/perl/clipboard
then add lines in ~/.Xdefaults:

URxvt.perl-ext-common: clipboard
URxvt.keysym.Mod4-c: perl:clipboard:copy
URxvt.keysym.Mod4-v: perl:clipboard:paste

should have a good work for copy/paste via Win+C/V cool

Edit: changed the method piping to xsel, avoid escape sequence problem.

wow! nice. thank you.

i didn't update this thread for a while, but i noticed that the earlier xdotool based solutions (including mine and Procyon's) sometimes just don't work, and I don't know why sad i will try this approach for a while smile
btw is there no recommed userspace location for urxvt scripts? otherwise, package your script please wink


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#25 2010-08-18 10:48:28

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Urxvt pasting from clipboard.. efficient, fast, clean

FWIW I'm now using http://github.com/muennich/urxvt-perls/ … /clipboard (found it thanks to https://bbs.archlinux.org/viewtopic.php?id=102972), which is pretty similar to realturner's script (it doesn't do the `pid = .. or die` stuff, it can also paste while escaping all special characters)
And to answer my own question: you can put your scripts in a per-user location, which is explained @ http://github.com/muennich/urxvt-perls (short answer: set URxvt.perl-lib in your .Xdefaults)
the guy also has some other cool urxvt scripts


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

Board footer

Powered by FluxBB