Last active
December 26, 2015 11:29
-
-
Save snipsnipsnip/c91c558fb629fbc6a2c6 to your computer and use it in GitHub Desktop.
mery macro: eval-ruby.js
This file contains hidden or 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
| if (document.selection.IsEmpty) { | |
| document.selection.EndOfLine(false, mePosLogical) | |
| document.selection.StartOfLine(true, mePosLogical) | |
| } | |
| var shell = new ActiveXObject('WScript.Shell') | |
| shell.CurrentDirectory = document.Path || shell.SpecialFolders("Desktop") | |
| var exec = shell.Exec('rubyw.exe -rtimeout -e "STDERR.reopen STDOUT; $0 = STDIN.gets.rstrip; print begin; Timeout.timeout(2) { eval($_ = STDIN.read) }; rescue Exception; %_#<#{$!.class}:#{$!.message}>_ end"') | |
| exec.StdIn.WriteLine(document.FullName) | |
| exec.StdIn.Write(document.selection.Text) | |
| exec.StdIn.Close() | |
| document.selection.text = exec.StdOut.ReadAll() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$0にファイル名を入れてある$_に選択範囲のテキストを入れてあるスクリプトを
__END__で終わらせるとテキスト処理にべんり