1 | #! perl -w |
---|
2 | |
---|
3 | # http://triplefusion.net/system/macosx-clipboard |
---|
4 | |
---|
5 | # ---------------------------------------------------------------------- |
---|
6 | # File: macosx-clipboard |
---|
7 | # ---------------------------------------------------------------------- |
---|
8 | # |
---|
9 | # All portions of code are copyright by their respective author/s. |
---|
10 | # Copyright (c) 2006 Samuel Ljungkvist <salj@triplefusion.net> |
---|
11 | # |
---|
12 | # This program is free software; you can redistribute it and/or modify |
---|
13 | # it under the terms of the GNU General Public License as published by |
---|
14 | # the Free Software Foundation; either version 2 of the License, or |
---|
15 | # (at your option) any later version. |
---|
16 | # |
---|
17 | # This program is distributed in the hope that it will be useful, |
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | # GNU General Public License for more details. |
---|
21 | # |
---|
22 | # You should have received a copy of the GNU General Public License |
---|
23 | # along with this program; if not, write to the Free Software |
---|
24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
25 | # ---------------------------------------------------------------------- |
---|
26 | # |
---|
27 | |
---|
28 | # Modification by Matias Larre-Borges <larre-borges.com:devel>: |
---|
29 | # To allow this module to work with the rxvt-unicode from macports, |
---|
30 | # I had to avoid using Foundation.pm |
---|
31 | |
---|
32 | # Usage: put in your .Xdefaults the following lines |
---|
33 | |
---|
34 | # URxvt.perl-ext-common: macosx-clipboard |
---|
35 | # URxvt.keysym.M-c: perl:macosx-clipboard:copy |
---|
36 | # URxvt.keysym.M-v: perl:macosx-clipboard:paste |
---|
37 | |
---|
38 | use Fcntl (); |
---|
39 | use locale; |
---|
40 | use utf8; |
---|
41 | |
---|
42 | sub copy { |
---|
43 | my ($self) = @_; |
---|
44 | |
---|
45 | open(CLIPBOARD, "| pbcopy "); |
---|
46 | print CLIPBOARD $self->selection; |
---|
47 | close CLIPBOARD; |
---|
48 | () |
---|
49 | } |
---|
50 | |
---|
51 | sub paste { |
---|
52 | my ($self) = @_; |
---|
53 | my ($str); |
---|
54 | |
---|
55 | $str = `pbpaste`; |
---|
56 | $str =~ tr/\n/\r/; |
---|
57 | $self->tt_write($self->locale_encode($str)); |
---|
58 | () |
---|
59 | } |
---|
60 | |
---|
61 | sub on_user_command { |
---|
62 | my ($self, $cmd) = @_; |
---|
63 | |
---|
64 | if ($cmd eq "macosx-clipboard:copy") { |
---|
65 | $self->copy; |
---|
66 | } |
---|
67 | |
---|
68 | if ($cmd eq "macosx-clipboard:paste") { |
---|
69 | $self->paste; |
---|
70 | } |
---|
71 | |
---|
72 | () |
---|
73 | } |
---|
74 | |
---|