Skip to content

Instantly share code, notes, and snippets.

@tmsanrinsha
Last active December 10, 2015 13:38
Show Gist options
  • Save tmsanrinsha/4442117 to your computer and use it in GitHub Desktop.
Save tmsanrinsha/4442117 to your computer and use it in GitHub Desktop.
function! s:Paste64Copy() range
let l:tmp = @"
silent normal gvy
let l:selected = @"
let @" = l:tmp
let l:i = 0
let l:len = strlen(l:selected)
let l:escaped = ''
while l:i < l:len
let l:c = strpart(l:selected, l:i, 1)
if char2nr(l:c) < 128
let l:escaped .= printf("\\u%04x", char2nr(l:c))
else
let l:escaped .= l:c
endif
let l:i += 1
endwhile
call system('echo -en "' . l:escaped . '" | pbcopy > /dev/tty')
redraw!
endfunction
command! -range Paste64Copy :call s:Paste64Copy()
#!/usr/bin/env perl
use strict;
use warnings;
use MIME::Base64;
use Encode;
use constant TMUXLEN => 250;
use constant SCREENLEN => 510;
binmode STDIN, ':encoding(utf8)';
my $input = do {
local $/;
<STDIN>;
};
$input =~ s/ \n+ \z//xsm;
$input =~ s/\n/\r\n/g;
$input = encode_base64( encode('cp932', $input), q{} );
if( $ENV{TMUX}) {
print "\ePtmux;\e\e]52;;\e\\";
# 分割して送信
for(my $i = 0, my $len = length($input); TMUXLEN * $i < $len; $i++) {
my $str = substr($input, TMUXLEN * $i, TMUXLEN);
print "\ePtmux;$str\e\\";
}
print "\ePtmux;\e\e\\\\\e\\";
} elsif( $ENV{TERM} eq 'screen' ) {
print "\eP\e]52;;\e\\";
for(my $i = 0, my $len = length($input); SCREENLEN * $i < $len; $i++) {
my $str = substr($input, SCREENLEN * $i, SCREENLEN);
print "\eP$str\e\\";
}
print "\eP\x07\e\\";
} else {
print "\e]52;;$input\e\\";
}
@tmsanrinsha
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment