Last active
December 10, 2015 13:38
-
-
Save tmsanrinsha/4442117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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\\"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
説明はこちら
http://sanrinsha.lolipop.jp/blog/2013/01/10618.html