如何在TextMate中将行发送到在“终端"窗口中运行的irb进程? [英] How can I send an line in TextMate to an irb process running in an Terminal window?

查看:92
本文介绍了如何在TextMate中将行发送到在“终端"窗口中运行的irb进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在TextMate窗口打开的情况下进行编码,并在与其相邻的Terminal窗口中进行irb进程.我希望能够按以下步骤在TextMate中按一个按键序列:

I often code with a TextMate window open, and an irb process in a Terminal window adjacent to it. I want to be able to press a key sequence in TextMate which does the following:

  1. 复制当前选择,如果没有,则复制当前行.
  2. 将其粘贴到运行irb的最上方的终端"窗口中.
  3. 按Enter键,以便在irb窗口中执行代码行.

在R中进行编码时,我使用了这种交互式开发风格,发现它非常方便.我很确定emacs和SLIME也可以让您像这样工作. Ruby和TextMate是否可以?

I used this style of interactive development when coding in R and found it very convenient. I'm pretty sure emacs and SLIME also lets you work like this. Is it possible with Ruby and TextMate?

推荐答案

您必须创建一个Bundle Command和一个键盘快捷键才能做到这一点.

You must create a Bundle Command and a keyboard shortcut to do this.

  1. 在TextMate中,转到Bundles-> Bundle Editor
  2. 在我们自己的捆绑包中创建一个新命令.称其为在终端中执行"
  3. 将保存"设置为无",将输入"设置为选定文本",将或"设置为行".
  4. 设置输出为放弃
  5. 在激活"中选择您自己的快捷方式.我选择了Apple Shift U
  6. 将下面的命令粘贴到命令"框中(格式给我带来麻烦)
  7. 关闭Bundle Editor,然后选择Bundles-> Bundle Editor-> Reload Bundles
  8. 创建一个新文件,其中包含"puts"Hello World""行
  9. 在终端机中打开IRB
  10. 选择您刚在Textmate中编写的行,然后按键盘快捷键.
  11. 观看"Hello World"出现在IRB中.
  1. In TextMate go to Bundles -> Bundle Editor
  2. Create a new Command inside our own Bundle. Call it "Execute in Terminal"
  3. Set "Save" to Nothing, set "Input" to Selected Text and "or" to Line.
  4. Set "Output to Discard
  5. In "Activation" choose your own shortcut. I chose Apple Shift U
  6. Paste the command below into the "Command" box (formatting is causing me trouble)
  7. Close the Bundle Editor and then choose Bundles -> Bundle Editor -> Reload Bundles
  8. Create a new document containing the line 'puts "Hello World"'
  9. Open up IRB in Terminal
  10. Select the line you have just written in Textmate and press your keyboard shortcut.
  11. Watch as "Hello World" appears in IRB.

命令:

#!/usr/bin/ruby

input = STDIN.gets

`osascript << EOF

tell application "Terminal"
  activate
end tell

delay 1

tell application "System Events"
  keystroke "#{input.gsub('"', '\"')}"
  keystroke return
end tell

EOF`

这篇关于如何在TextMate中将行发送到在“终端"窗口中运行的irb进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆