Working with Ruby by Jan Lelis

Use fresh Ruby as your shell!

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.

Updated for fresh version 0.2.0.

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: /^\w+\s+.*/ (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> 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

The command used (as single word or first part of the regex) is looked for in Ripl.config[:fresh_system_commands] which contains the commands available in your path.

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> mv [TAB]
.README.rdoc.swp  CHANGELOG.rdoc    README.rdoc       bin/           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 and (sometimes) command completion is supported.

You can also use the command output in Ruby by assigning it to a Ruby expression. This is done like this:

~/a/ripl-fresh> ls => a
~/a/ripl-fresh> a
=> ["bin", "CHANGELOG.rdoc", "", "fresh.gemspec", "lib", "LICENSE", "pkg", "Rakefile", "README.rdoc"]
~/a/ripl-fresh> a.size
=> 9

Further information on github ;)

Creative Commons License


omg | November 24, 2010

J-_-L | November 24, 2010

Hi. rush feels different. It's a cool project, but it goes another way. In fresh, not every command you are writing is Ruby and has to obey its syntax - so you can, for example, call system commands with their string arguments, without using commas or quotes. However, rush has a much better interaction between the system calls and Ruby manipulation of those.

joeyrobert | November 25, 2010

Can you pipe process information into Ruby lambdas? That would be a killer feature. Good work so far.

grosser | November 25, 2010

Looks promising!

njs | November 25, 2010

Looks interesting ... will give it a try!

Just a thought - perhaps you could investigate using some method_missing magic, so that if the variable/method isn't defined in ruby (as in your 'cal' example), it tries executing at the shell.

(Could be some gotchas I haven't considered, but it was just a quick thought ...)

Spakman | November 25, 2010

Interesting looking stuff - well done!

I've also been creating a shell in Ruby. Urchin ( is an implementation of a more standard Unix shell - job control, pipelines and the like.

I was planning to delimit Ruby code with special strings, but your regex approach has me reconsidering if there's another way...

yonkeltron | November 25, 2010

I wonder if a regex isn't rather fragile. Have you considered a more robust approach, possibly with a parser or a durable guessing strategy? Since the grammar of the shell is much less complex than the grammar of Ruby itself, you could first try to see if the command is a shell command and, if not, pass it to Ruby for evaluation.

J-_-L | November 25, 2010

Thanks for this nice feedback :)
@joeyrobert Yep, that would be cool ;).
@njs I've thought about it, but I think I'll keep that <code>method_missing</code> space clean and only use the regex detection
@Spakman Thanks for that pointer, I'll take a look at it
@yonkeltron I'll defenitely stick to the regex approach for some time, but maybe change that later and/or add tests ;)

Daniel | November 25, 2010

I wrote rubsh quite awhile ago to do this. Feel free to try it out. No pipes to ruby commands, and no jobs management however, but works pretty well.

Pavel | November 25, 2010

It can be interesting, I think i should try ...

Aki | May 15, 2011

By the way, in the file lib/bond/completions/ripl-fresh.rb the everything_completion causes some completions to fail. Filename completions work, method completions work, but if I try to tab a ruby word, it gives me error. So:

file[Tab] <= works
[Space]Object.[Tab] <= works
[Space]Obje[Tab][Tab] <= throws:
Bond Error: Failed during completion action with 'undefined method `+' for nil:NilClass'.

Commenting out the completion in ripl-fresh.rb makes everything work again.

J-_-L | May 22, 2011

@Aki: Thanks for the feeback, I'll take a look at this.

Antonia | August 22, 2015

Where do you come from? purchase hydroxyzine online "I am very pleased that they have been ejected, but I think it is enormously worrying that it takes a question in parliament to make DSEI do their jobs properly. One can have no confidence that the policy on selling illegal weapons is being upheld properly at all."

Dogkill | August 22, 2015

I'm only getting an answering machine how much does amoxicillin cost in canada Segarra claims the defendants harmed her career andreputation by firing her for cause. She seeks an order statingthey illegally interfered with her bank examination andreinstating her to her job. Segarra also asked for unspecifieddamages.

Goodsam | August 22, 2015

Which team do you support? atarax cost Fitzpatrick, meanwhile, said he hoped to "tone the rhetoric down a little bit" in the dispute over the Legislature's refusal to turn over information about their outside income, but he stressed "we're going to get that information one way or the other. I can assure you of that."

Manuel | August 22, 2015

Could I have , please? atarax hydroxyzine The company wrote down more than 1 billion euros worth ofassets in the quarter to cover the falling value of gas plantsin Austria and France, renewable energy projects, a minorityinterest in Italian energy group Sorgenia and other interests.

Clyde | August 22, 2015

A packet of envelopes much does accutane cost australia Mr Vine's official inspection review also found that hundreds of thousands of suspected cases of drug smuggling were not investigated last year because border guards were "prioritising" immigration checks.

Emanuel | August 22, 2015

i'm fine good work generic cymbalta 2013 However ministers are publishing new guidance which will replace this with much tougher protections for the green belt, which covers over 6,000 square miles of countryside around towns and cities to prevent urban sprawl.

Donald | August 22, 2015

How long have you lived here? buy ciprofloxacin 500mg Venezuelans who possess an international airline ticket can exchange their bolivars for dollars through the Venezuela foreign exchange agency at the state-set rate of 6.3 bolivars per dollar. One can get up to $3,000 in U.S. dollars this way.

Norbert | August 22, 2015

I'm doing an internship amoxicillin online buy uk “The lack of transparency when it comes to whether food is freshly prepared and where it comes from is worrying. Those chains which maintain that attitude are in danger of families voting with their feet and choosing to eat elsewhere.”

Ferdinand | August 22, 2015

How long have you lived here? generic duloxetine 60 mg He thinks anonymity should be granted to both defendant and complainant in cases of alleged sexual offences, but with the provision for an application to be made to a judge if the suspect is thought to be a serial offender or there is a hope other victims or witnesses might come forward.

Glenn | August 22, 2015

Languages cheap cymbalta These are important measures if implemented well, but even so, stop drastically short of what is needed if we want to end what some activists call India&#8217;s &#8220;rape epidemic&#8221; &#8211; where a rape occurs every 21 minutes.

Maxwell | August 23, 2015

This is your employment contract <a href=" ">cardura e10p msds</a> Bar Refaeli is one dirty lady! The model posted Twitter pictures of herself relaxing by the Dead Sea -- and it was not what we would call good, clean fun. The beauty wrote on Aug. 10, 2011: '*muddy* but feels good!! DEAD SEA- if you haven't been ... well, sucks for you!'

Amado | August 23, 2015

We'd like to offer you the job <a href=" ">where can i buy zithromax azithromycin</a> "It&#039;s comforting to see some stabilisation in core services prices," said Laura Rosner, economist at BNP Paribas in New York, adding that "we expect personal consumption to remain weak".

Crazyivan | August 23, 2015

I can't get through at the moment <a href=" ">vermox worm tablets</a> Michael Daragjati, who is serving a 57-month sentence in an Ohio federal prison for violating the civil rights of Kenrick Gray and an unrelated extortion conviction, acted as his own lawyer in settling the separate civil suit July 30.

Edgar | August 23, 2015

Insert your card <a href=" ">generic propecia finasteride 5mg</a> Trainer and consultant of Telephone Consultation Services who trains on behalf of the RGCP said: &ldquo;Experience as a GP or nurse is not enough. Conversely, many treat it very carefully or have a lot more concern about it than others &ndash; terrified in fact of not seeing their patients, which results in a high conversion rate to face to face appointments.&rdquo;

Paige | August 23, 2015

I'm a partner in <a href=" ">rogaine rebate program</a> "Perseverance is going to be the key for all of us. I'll be flat out all the way working as hard as I can to drive them to success. It's a team effort not a one-man band but I want them to know that whilst they are putting in 100 per cent I'll be doing the same. This is a new time for me and I feel I have equally good people here working just as hard as anyone else.

Marshall | August 23, 2015

I'd like to send this letter by <a href=" ">women's rogaine best price</a> Copper and oil prices rebounded from early losses on hopesfor good results from China's economic efforts, while yields onlow-risk U.S. and German government debt rose as higher equityprices reduced their safe-haven appeal.

Freddy | August 23, 2015

I'm a partner in <a href=" ">ventolin hfa price comparison</a> The targets are the vast oil fields in the Santa Barbara Channel, site of a 1969 spill that spewed more than 3 million gallons of crude oil into the ocean, spoiled miles of beaches and killed thousands of birds and other wildlife. The disaster prompted a moratorium on new drill leases and inspired federal clean water laws and the modern environmental movement.

Ricardo | August 23, 2015

Have you got a telephone directory? <a href=" ">megalis generic</a> The company lowered its outlook for the year for revenue excluding commissions, expecting revenue of at up to $4.45 billion, compared with an estimate three months ago of as much as $4.55 billion. Yahoo also lowered its forecast for operating income to as much as $860 million, from a previous ceiling of $1 billion.

Lance | August 23, 2015

I'll call back later <a href=" ">zantac 30 mg</a> That was the message from workers at the city&#8217;s port, alarmed at calls to outlaw cruise ships from the tourist destination in the wake of Italy&#8217;s Costa Concordia disaster and amid fears over structural damage and pollution.

Booker | August 23, 2015

We work together <a href=" ">purchase valtrex online</a> It's a market that's as much about style as it is about sound, and years after LeBron and others popularized those classic Studios, that style was — and is — bound to change. An upgrade was crucial.

You? | September 01, 2015