Hi all,
Previous conversations on related topics to this don't seem to answer the question (correct me if I'm wrong!), so:
Can I turn the input to a command script into a shell variable, i.e. is there a UNIXy way of reading stdin into a variable?
To be more concrete, I have a simple command for looking up the current word in the R help files (which are in HTML) and displaying the page in TM's browser. The basic command is
#! /usr/bin/ruby text = STDIN.read file = `find /Library/Frameworks/R.framework/Versions/Current/Resources/library -name #{text}.html -print` html = `cat #{file}` print html
This works, but seems like an inelegant solution, and for more complex tasks it would be useful to know how to avoid needing ruby and make this something like
var=[something] cat `find /Library/Frameworks/R.framework/Versions/Current/Resources/library -name $var.html -print`
TIA! Jon
(smacks head)
Sorry - I'm being very slow. Of course, "read" will do what I want. Hopefully other R users may find this "Show in R help" command useful though.
read name cat `find /Library/Frameworks/R.framework/Versions/Current/Resources/library -name $name.html -print`
On 14/07/06, Jonathan Clayden jon.clayden@gmail.com wrote:
Hi all,
Previous conversations on related topics to this don't seem to answer the question (correct me if I'm wrong!), so:
Can I turn the input to a command script into a shell variable, i.e. is there a UNIXy way of reading stdin into a variable?
To be more concrete, I have a simple command for looking up the current word in the R help files (which are in HTML) and displaying the page in TM's browser. The basic command is
#! /usr/bin/ruby text = STDIN.read file = `find /Library/Frameworks/R.framework/Versions/Current/Resources/library -name #{text}.html -print` html = `cat #{file}` print html
This works, but seems like an inelegant solution, and for more complex tasks it would be useful to know how to avoid needing ruby and make this something like
var=[something] cat `find /Library/Frameworks/R.framework/Versions/Current/Resources/library -name $var.html -print`
TIA! Jon
Yes, or also:
cat `find /Library/Frameworks/R.framework/Versions/Current/Resources/ library -name "$TM_CURRENT_WORD.html" -print` or cat `find /Library/Frameworks/R.framework/Versions/Current/Resources/ library -name "$TM_CURRENT_SELECTION.html" -print`
would work here too.
Good idea, thanks!
Once you open an R help page in this way, the hyperlinks don't work. Anyone know if it's possible to fix that?
On 14 Jul 2006, at 18:14, Jonathan Clayden wrote:
(smacks head)
Sorry - I'm being very slow. Of course, "read" will do what I want. Hopefully other R users may find this "Show in R help" command useful though.
read name cat `find /Library/Frameworks/R.framework/Versions/Current/ Resources/library -name $name.html -print`
On 14/07/06, Jonathan Clayden jon.clayden@gmail.com wrote:
Hi all,
Previous conversations on related topics to this don't seem to answer the question (correct me if I'm wrong!), so:
Can I turn the input to a command script into a shell variable, i.e. is there a UNIXy way of reading stdin into a variable?
To be more concrete, I have a simple command for looking up the current word in the R help files (which are in HTML) and displaying the page in TM's browser. The basic command is
#! /usr/bin/ruby text = STDIN.read file = `find /Library/Frameworks/R.framework/Versions/Current/ Resources/library -name #{text}.html -print` html = `cat #{file}` print html
This works, but seems like an inelegant solution, and for more complex tasks it would be useful to know how to avoid needing ruby and make this something like
var=[something] cat `find /Library/Frameworks/R.framework/Versions/Current/ Resources/library -name $var.html -print`
TIA! Jon
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 14/07/06, Ana Nelson nelson.ana@gmail.com wrote:
Yes, or also:
cat `find /Library/Frameworks/R.framework/Versions/Current/Resources/ library -name "$TM_CURRENT_WORD.html" -print` or cat `find /Library/Frameworks/R.framework/Versions/Current/Resources/ library -name "$TM_CURRENT_SELECTION.html" -print`
would work here too.
True, although it's useful to let TM itself decide whether to use word or selection.
Once you open an R help page in this way, the hyperlinks don't work. Anyone know if it's possible to fix that?
Back to Ruby! This is a little quick and dirty, but it seems to work fine:
#! /usr/bin/ruby text = STDIN.read file = `find /Library/Frameworks/R.framework/Versions/Current/Resources/library -name #{text}.html -print` unless file.empty? dir = File.dirname(file) html = `cat #{file}` print html.gsub(/href=['"]([^'"]+)['"]/, "href="tm-file://#{dir}/\1"") end
On Jul 14, 2006, at 1:24 PM, Jonathan Clayden wrote:
On 14/07/06, Ana Nelson nelson.ana@gmail.com wrote:
Once you open an R help page in this way, the hyperlinks don't work. Anyone know if it's possible to fix that?
Back to Ruby! This is a little quick and dirty, but it seems to work fine:
Very cool, Jonathan and Ana. I had been sending help commands to R itself, but that usually meant my R window came to the front along with the help window. This allows one to keep R out of the way until it's wanted. (And the links work, which is great.)
-Alan