Simple image host.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

clipboard 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #! perl -w
  2. # Author: Bert Muennich
  3. # Website: http://www.github.com/muennich/urxvt-perls
  4. # License: GPLv2
  5. # Use keyboard shortcuts to copy the selection to the clipboard and to paste
  6. # the clipboard contents (optionally escaping all special characters).
  7. # Requires xsel to be installed!
  8. # Usage: put the following lines in your .Xdefaults/.Xresources:
  9. # URxvt.perl-ext-common: ...,clipboard
  10. # URxvt.keysym.M-c: perl:clipboard:copy
  11. # URxvt.keysym.M-v: perl:clipboard:paste
  12. # URxvt.keysym.M-C-v: perl:clipboard:paste_escaped
  13. # Options:
  14. # URxvt.clipboard.autocopy: If true, PRIMARY overwrites clipboard
  15. # You can also overwrite the system commands to use for copying/pasting.
  16. # The default ones are:
  17. # URxvt.clipboard.copycmd: xsel -ib
  18. # URxvt.clipboard.pastecmd: xsel -ob
  19. # If you prefer xclip, then put these lines in your .Xdefaults/.Xresources:
  20. # URxvt.clipboard.copycmd: xclip -i -selection clipboard
  21. # URxvt.clipboard.pastecmd: xclip -o -selection clipboard
  22. # On Mac OS X, put these lines in your .Xdefaults/.Xresources:
  23. # URxvt.clipboard.copycmd: pbcopy
  24. # URxvt.clipboard.pastecmd: pbpaste
  25. # The use of the functions should be self-explanatory!
  26. use strict;
  27. sub on_start {
  28. my ($self) = @_;
  29. $self->{copy_cmd} = $self->x_resource('clipboard.copycmd') || 'xsel -ib';
  30. $self->{paste_cmd} = $self->x_resource('clipboard.pastecmd') || 'xsel -ob';
  31. if ($self->x_resource('clipboard.autocopy') eq 'true') {
  32. $self->enable(sel_grab => \&sel_grab);
  33. }
  34. ()
  35. }
  36. sub copy {
  37. my ($self) = @_;
  38. if (open(CLIPBOARD, "| $self->{copy_cmd}")) {
  39. my $sel = $self->selection();
  40. utf8::encode($sel);
  41. print CLIPBOARD $sel;
  42. close(CLIPBOARD);
  43. } else {
  44. print STDERR "error running '$self->{copy_cmd}': $!\n";
  45. }
  46. ()
  47. }
  48. sub paste {
  49. my ($self) = @_;
  50. my $str = `$self->{paste_cmd}`;
  51. if ($? == 0) {
  52. $self->tt_paste($str);
  53. } else {
  54. print STDERR "error running '$self->{paste_cmd}': $!\n";
  55. }
  56. ()
  57. }
  58. sub paste_escaped {
  59. my ($self) = @_;
  60. my $str = `$self->{paste_cmd}`;
  61. if ($? == 0) {
  62. $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
  63. $self->tt_paste($str);
  64. } else {
  65. print STDERR "error running '$self->{paste_cmd}': $!\n";
  66. }
  67. ()
  68. }
  69. sub on_action {
  70. my ($self, $action) = @_;
  71. on_user_command($self, "clipboard:" . $action);
  72. }
  73. sub on_user_command {
  74. my ($self, $cmd) = @_;
  75. if ($cmd eq "clipboard:copy") {
  76. $self->copy;
  77. } elsif ($cmd eq "clipboard:paste") {
  78. $self->paste;
  79. } elsif ($cmd eq "clipboard:paste_escaped") {
  80. $self->paste_escaped;
  81. }
  82. ()
  83. }
  84. sub sel_grab {
  85. my ($self) = @_;
  86. $self->copy;
  87. ()
  88. }