[英]How can I send an line in TextMate to an irb process running in an Terminal window?
我經常使用TextMate窗口打開代碼,並在與其相鄰的終端窗口中進行irb處理。 我希望能夠在TextMate中按下一個鍵序列,它執行以下操作:
我在R中編碼時使用了這種交互式開發方式,發現非常方便。 我很確定emacs和SLIME也讓你像這樣工作。 Ruby和TextMate有可能嗎?
您必須創建一個Bundle Command和一個鍵盤快捷鍵才能執行此操作。
命令:
#!/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中,就像在Smalltalk工作區中一樣。
實質上,您希望在文本配合中運行ruby,但是您希望在執行之間記住變量。 你可以擁有它。
(感謝stef獲取有關如何添加新命令的說明)
gem install daemons
@@hi = "Hello World"
和@@hi + "ya"
行的新文檔 irb服務器:
#!/usr/bin/env ruby -w
require 'rubygems'
require 'daemons'
require 'socket'
LARGE = 100000000
PIPE = "/tmp/.irbservepipe"
def kill_pipe
`rm -f #{PIPE}`
end
def respond_to(pipe)
inp = pipe.recv LARGE
inp.nil? and return
begin
out = eval(inp)
rescue Exception => e
out = e
end
pipe.send out.inspect, 0
end
def ensure_server
["EXIT", "INT", "HUP", "TERM"].each {|ea| trap( ea ) { kill_pipe }}
File.exists?(PIPE) and kill_pipe
server = UNIXServer.new(PIPE)
loop {
c = server.accept
respond_to c
c.close
}
end
Daemons.daemonize
ensure_server
命令:
#!/usr/bin/env macruby -w
require 'socket'
LARGE = 100000000
PIPE = "/tmp/.irbservepipe"
input = STDIN.read
socket = UNIXSocket.new(PIPE)
socket.send input, 0
puts socket.recv LARGE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.