This post originated from an RSS feed registered with Ruby Buzz
by Jan Lelis.
Original Post: Use fresh Ruby as your shell!
Feed Title: rbJ*_*L.net
Feed URL: http://feeds.feedburner.com/rbJL
Feed Description: Hi, I am a fan of Ruby and like to explore it and the world around ;).
So I started this blog, where I am publishing code snippets, tutorials for beginners as well as general thoughts about Ruby, the web or programming in general.
Fresh tries to detect automatically, if your expression should be a Ruby or a shell command. Basically, this is done by a regexp similar to this one: /^([a-z_-]+)\s+/i (match a single word followed by at least one space):
~/a/ripl-fresh> 3.times{ puts "This is Ruby" }
This is Ruby
This is Ruby
This is Ruby
=> 3
~/a/ripl-fresh> cd lib/ripl
~/a/ripl-fresh/lib/ripl> ls
fresh fresh.rb
~/a/ripl-fresh/lib/ripl> vim fresh.rb
~/a/ripl-fresh/lib/ripl>cd -
~/a/ripl-fresh>ps -ax
It now shows my current processes – as expected. But note: The regexp matches for a single word and a space, so a single ps would result in a syntax error. It’s this way, because it’s hard to determine what you want to do with one single word. Fresh defaults to Ruby, except the words defined in the configuration (like ls). You can modify it like this: @Ripl.config[:fresh_system_words] << ‘ps’.
You can also force the line to be interpreted as Ruby by prefixing it with a space, or to force interpretation as system command by prefixing it with ^:
~/a/ripl-fresh> cal
NameError: undefined local variable or method `cal' for main:Object ...
~/a/ripl-fresh> ^cal
November 2010
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
~/a/ripl-fresh> mv [TAB]
.README.rdoc.swp CHANGELOG.rdoc README.rdoc bin/ deps.rip pkg/
.gemspec LICENSE.txt Rakefile blog.textile lib/
~/a/ripl-fresh> mv LICENSE.txt LICENSE
Fresh comes with a very basic auto-completion: currently, only path completion is supported.