6

I just started using R on Terminal because its tab function. But I have no idea how to send the selected text in TextMate to the Terminal. Could expertise show me how to write the Command in TextMate?

Thanks!

Naiqi
  • 65
  • 4
  • This question is independent of R. Here is one nice Q/A showing how to do it with ruby. http://stackoverflow.com/questions/4524400/how-can-i-send-an-line-in-textmate-to-an-irb-process-running-in-an-terminal-wind – John Colby Feb 09 '12 at 20:47
  • Thanks John, It works! I don't know why it didn't this morning. – Naiqi Feb 09 '12 at 21:18
  • 1
    Maybe it just needed a "Reload Bundles"? Also, have you checked out the [R.tmbundle](https://github.com/textmate/r.tmbundle)? It has some other useful R TextMate stuff, including a similar "Send to..." command. That one uses bash instead of ruby, but notice that they both actually just use applescript under the hood. – John Colby Feb 09 '12 at 21:24
  • I have no idea of what is ruby or bash, is it possible to change it from using bash to ruby, which then make the sending to Terminal possible? – Naiqi Feb 09 '12 at 22:15
  • The method of using ruby seems not very efficient, and resulted some errors which never happened in R.app. I changed term "R" in the bash based command to "Terminal", but nothing showed up in Terminal. – Naiqi Feb 09 '12 at 22:18

2 Answers2

9

Here is the exact TextMate command that I currently use. Hope it helps!

rawText="$(cat | sed 's/ / /g;')" 

osascript  -e 'on run(theCode)' \
           -e '  tell application "Terminal"' \
           -e '    do script theCode in window 1' \
           -e '  end tell' \
           -e 'end run' -- "$rawText"

open "txmt://open?line=$(($TM_LINE_NUMBER+1))&column=1000000" &

enter image description here

John Colby
  • 22,169
  • 4
  • 57
  • 69
1

TextMate is MacOS, right? Is so, then this is from the R ?connections page:

"Mac OS X users can use pipe("pbpaste") and pipe("pbcopy", "w") to read from and write to that system's clipboard."

You can "paste" from R-Clipboards into Terminal sessions. You can also send file content from TextMate: http://manual.macromates.com/en/shell_commands#executing_commands_filtering_text

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Thanks, but I still have no idea how to. What I need is simply a command set in the Bundle, which makes me send the selected text to Terminal directly. – Naiqi Feb 09 '12 at 21:10