Skip to content

Instantly share code, notes, and snippets.

@sago35
Created September 18, 2015 09:08
Show Gist options
  • Save sago35/bbb2bdf38f2bc2fca668 to your computer and use it in GitHub Desktop.
Save sago35/bbb2bdf38f2bc2fca668 to your computer and use it in GitHub Desktop.
script for rewriting clipboard
use strict;
use warnings;
use utf8;
use Clipboard;
use Path::Tiny;
use Encode;
my $cp932 = Encode::find_encoding("cp932");
my $utf8 = Encode::find_encoding("utf8");
my $clip = $cp932->decode(Clipboard->paste);
printf "[input]\n";
printf "%s\n", $cp932->encode($clip);
printf "--\n";
printf "\n";
my $path = Path::Tiny->tempfile;
$path->spew_utf8($clip);
system "gvim", $path;
my $modified = $path->slurp_utf8;
if ($clip ne $modified) {
my $str = $cp932->encode($modified);
Clipboard->copy($str);
printf "[modified]\n";
printf "%s\n", $str;
printf "--\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment