Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
Last active December 26, 2015 11:29
Show Gist options
  • Select an option

  • Save snipsnipsnip/c91c558fb629fbc6a2c6 to your computer and use it in GitHub Desktop.

Select an option

Save snipsnipsnip/c91c558fb629fbc6a2c6 to your computer and use it in GitHub Desktop.
mery macro: eval-ruby.js
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()
@snipsnipsnip
Copy link
Author

$0にファイル名を入れてある
$_に選択範囲のテキストを入れてある
スクリプトを__END__で終わらせるとテキスト処理にべんり

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