Debian Codegraph @

scripts/clipfilter

raw
1 #!/usr/bin/perl
2
3 # PODNAME: clipfilter
4 use strict;
5 use warnings;
6 use Clipboard;
7 my %methods = (
8 -html => sub { require CGI; CGI::escapeHTML($_[0]) },
9 -uri => sub { require URI::Escape; URI::Escape::uri_escape($_[0]) },
10 );
11
12 my $result = filter($ARGV[0], Clipboard->paste);
13 Clipboard->copy($result);
14 print $result, "\n... is now in the clipboard.\n";
15
16 sub filter {
17 my ($method, $data) = @_;
18 if (exists $methods{$method}) {
19 return $methods{$method}->($data);
20 } else {
21 require IPC::Open2;
22 my ($child_out, $child_in);
23 my $cmd_text = join ' ', @ARGV; # just for error message output
24 my $pid = IPC::Open2::open2($child_out, $child_in, @ARGV)
25 or die "Couldn't open pipe to `$cmd_text`: $!";
26
27 print {$child_in} $data or die "Couldn't write to `$cmd_text`: $?";
28 close $child_in or die "Couldn't close 'in' for `$cmd_text`: $?";
29 my $ret = join '', <$child_out>; # Hrmm... error handling?
30 close $child_out or die "Couldn't close 'out' for `$cmd_text`: $?";
31
32 waitpid($pid, 0);
33 die "Child error for `$cmd_text`: $?" if $? >> 8;
34 return $ret;
35 }
36 }
37
38 __END__
39
40 =pod
41
42 =encoding UTF-8
43
44 =head1 NAME
45
46 clipfilter - Run various conversions for your clipboard data.
47
48 =head1 VERSION
49
50 version 0.32
51
52 =head1 USAGE
53
54 # (copy some stuff)
55 $ clipfilter -html
56 # (paste, with html entities substituted in)
57
58 # or URI-escaping:
59 $ clipfilter -uri
60
61 # or pipe through an arbitrary program, like `tac`, the backwards cat:
62 $ clipfilter tac
63 # Note: currently, this just dumps everything to open2() and reads
64 # everything back. It could possibly create a deadlock, but I haven't
65 # found the case that causes this, yet.
66
67 =head1 MOTIVATION
68
69 A very frequent user pattern is to copy something, edit it in some rote way,
70 and then paste it back. Writing your own filter scripts will make it even more
71 useful.
72
73 =head1 BUGS
74
75 Current weirdness when piping this to some programs, like 'wc' and 'tail'.
76 I will work on this.
77
78 =head1 AUTHOR
79
80 Ryan King <[email protected]>
81
82 =head1 COPYRIGHT
83
84 Copyright (c) 2010. Ryan King. All rights reserved.
85
86 This program is free software; you can redistribute it and/or modify it
87 under the same terms as Perl itself.
88
89 See L<http://www.perl.com/perl/misc/Artistic.html>
90
91 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
92
93 =head1 SUPPORT
94
95 =head2 Websites
96
97 The following websites have more information about this module, and may be of help to you. As always,
98 in addition to those websites please use your favorite search engine to discover more resources.
99
100 =over 4
101
102 =item *
103
104 MetaCPAN
105
106 A modern, open-source CPAN search engine, useful to view POD in HTML format.
107
108 L<https://metacpan.org/release/Clipboard>
109
110 =item *
111
112 RT: CPAN's Bug Tracker
113
114 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
115
116 L<https://rt.cpan.org/Public/Dist/Display.html?Name=Clipboard>
117
118 =item *
119
120 CPANTS
121
122 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
123
124 L<http://cpants.cpanauthors.org/dist/Clipboard>
125
126 =item *
127
128 CPAN Testers
129
130 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
131
132 L<http://www.cpantesters.org/distro/C/Clipboard>
133
134 =item *
135
136 CPAN Testers Matrix
137
138 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
139
140 L<http://matrix.cpantesters.org/?dist=Clipboard>
141
142 =item *
143
144 CPAN Testers Dependencies
145
146 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
147
148 L<http://deps.cpantesters.org/?module=Clipboard>
149
150 =back
151
152 =head2 Bugs / Feature Requests
153
154 Please report any bugs or feature requests by email to C<bug-clipboard at rt.cpan.org>, or through
155 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=Clipboard>. You will be automatically notified of any
156 progress on the request by the system.
157
158 =head2 Source Code
159
160 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
161 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
162 from your repository :)
163
164 L<https://github.com/shlomif/Clipboard>
165
166 git clone git://github.com/shlomif/Clipboard.git
167
168 =head1 AUTHOR
169
170 Shlomi Fish <[email protected]>
171
172 =head1 BUGS
173
174 Please report any bugs or feature requests on the bugtracker website
175 L<https://github.com/shlomif/Clipboard/issues>
176
177 When submitting a bug or request, please include a test-file or a
178 patch to an existing test-file that illustrates the bug or desired
179 feature.
180
181 =head1 COPYRIGHT AND LICENSE
182
183 This software is copyright (c) 2025 by Ryan King <[email protected]>.
184
185 This is free software; you can redistribute it and/or modify it under
186 the same terms as the Perl 5 programming language system itself.
187
188 =cut