Debian Codegraph @

scripts/clipedit

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/perl
2
3 # PODNAME: clipedit
4 use strict;
5 use warnings;
6
7 use Clipboard;
8 use File::Temp qw( tempfile );
9
10 my $orig = Clipboard->paste;
11
12 my ($tmp_fh, $tmpfilename) = tempfile();
13 print {$tmp_fh} $orig;
14 close $tmp_fh;
15
16 my $ed = $ENV{VISUAL} || $ENV{EDITOR} || 'vim';
17 system($ed, $tmpfilename);
18
19 sub _slurp
20 {
21 my $filename = shift;
22
23 open my $in, '<', $filename
24 or die "Cannot open '$filename' for slurping - $!";
25
26 local $/;
27 my $contents = <$in>;
28
29 close($in);
30
31 return $contents;
32 }
33
34 my $edited = _slurp($tmpfilename);
35
36 my $current = Clipboard->paste;
37
38 if ($current ne $orig) {
39 local $| = 1;
40 boldprint("1) When you started, the Clipboard contained:\n");
41 print $orig;
42 boldprint("\n2) ...but now the Clipboard contains:\n");
43 print $current;
44 boldprint("\n3) and you edited to this:\n");
45 print $edited;
46 boldprint("\nWhich would you like to use (1, 2, or the default, 3)? ");
47 my %actions = (
48 1 => $orig,
49 2 => $current,
50 3 => $edited,
51 );
52 my $answer;
53 while (1) {
54 $answer = <STDIN>;
55 chomp $answer;
56 $answer = 3 if $answer eq '';
57 last if exists $actions{$answer};
58 my @puzzles = qw(hrm what huh uhh who because sneevle);
59 boldprint(ucfirst($puzzles[int rand $#puzzles]) . "? ");
60 }
61 $edited = $actions{$answer};
62 }
63 Clipboard->copy($edited);
64 print Clipboard->paste;
65 boldprint("\n...is now in the Clipboard\n");
66
67 unlink($tmpfilename) or die "Couldn't remove $tmpfilename: $!";
68
69 sub boldprint {
70 # If you are in a situation where this output is annoying, such as in a
71 # DOS console without ANSI parsing, please send a patch. For now, I'll
72 # just do the simplest thing and print it every time:
73 printf "\e[033m%s\e[0m", shift;
74 }
75
76 __END__
77
78 =pod
79
80 =encoding UTF-8
81
82 =head1 NAME
83
84 clipedit - Edit clipboard contents in one swoop.
85
86 =head1 VERSION
87
88 version 0.32
89
90 =head1 MOTIVATION
91
92 Eliminating the "Open editor, edit stuff, copy back to the clipboard" shuffle.
93
94 =head1 NOTE
95
96 If for some reason the clipboard contents changes during the edit session, you
97 will be prompted to choose between 1) the original Clipboard contents, 2) the
98 new Clipboard contents, and 3) the result of your edits (which is the default
99 if you just hit "Enter").
100
101 =head1 CONFIGURATION
102
103 If you don't want the script to use C<vim> to edit, set either the
104 environment variable C<$VISUAL> or C<$EDITOR>.
105
106 =head1 AUTHOR
107
108 Ryan King <[email protected]>
109
110 =head1 COPYRIGHT
111
112 Copyright (c) 2010. Ryan King. All rights reserved.
113
114 This program is free software; you can redistribute it and/or modify it
115 under the same terms as Perl itself.
116
117 See L<http://www.perl.com/perl/misc/Artistic.html>
118
119 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
120
121 =head1 SUPPORT
122
123 =head2 Websites
124
125 The following websites have more information about this module, and may be of help to you. As always,
126 in addition to those websites please use your favorite search engine to discover more resources.
127
128 =over 4
129
130 =item *
131
132 MetaCPAN
133
134 A modern, open-source CPAN search engine, useful to view POD in HTML format.
135
136 L<https://metacpan.org/release/Clipboard>
137
138 =item *
139
140 RT: CPAN's Bug Tracker
141
142 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
143
144 L<https://rt.cpan.org/Public/Dist/Display.html?Name=Clipboard>
145
146 =item *
147
148 CPANTS
149
150 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
151
152 L<http://cpants.cpanauthors.org/dist/Clipboard>
153
154 =item *
155
156 CPAN Testers
157
158 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
159
160 L<http://www.cpantesters.org/distro/C/Clipboard>
161
162 =item *
163
164 CPAN Testers Matrix
165
166 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
167
168 L<http://matrix.cpantesters.org/?dist=Clipboard>
169
170 =item *
171
172 CPAN Testers Dependencies
173
174 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
175
176 L<http://deps.cpantesters.org/?module=Clipboard>
177
178 =back
179
180 =head2 Bugs / Feature Requests
181
182 Please report any bugs or feature requests by email to C<bug-clipboard at rt.cpan.org>, or through
183 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=Clipboard>. You will be automatically notified of any
184 progress on the request by the system.
185
186 =head2 Source Code
187
188 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
189 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
190 from your repository :)
191
192 L<https://github.com/shlomif/Clipboard>
193
194 git clone git://github.com/shlomif/Clipboard.git
195
196 =head1 AUTHOR
197
198 Shlomi Fish <[email protected]>
199
200 =head1 BUGS
201
202 Please report any bugs or feature requests on the bugtracker website
203 L<https://github.com/shlomif/Clipboard/issues>
204
205 When submitting a bug or request, please include a test-file or a
206 patch to an existing test-file that illustrates the bug or desired
207 feature.
208
209 =head1 COPYRIGHT AND LICENSE
210
211 This software is copyright (c) 2025 by Ryan King <[email protected]>.
212
213 This is free software; you can redistribute it and/or modify it under
214 the same terms as the Perl 5 programming language system itself.
215
216 =cut