The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Use fresh Ruby as your shell!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jan Lelis

Posts: 136
Nickname: rbjl
Registered: Aug, 2009

Jan Lelis is an IT student from Dresden/Germany
Use fresh Ruby as your shell! Posted: Nov 24, 2010 12:27 PM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jan Lelis
Latest Posts From rbJ*_*L.net

Advertisement

We love Ruby. And we love the command line. So… the shell needs to be rubyfied ;).

Fresh is a new gem, trying to achieve this.

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.

Further information on github ;)

CC-BY (DE)

Read: Use fresh Ruby as your shell!

Topic: Homesteading at indieconf Previous Topic   Next Topic Topic: Don't Know Metaprogramming In Ruby?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use