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.

Danilo | September 01, 2015

I'm happy very good site <a href=" ">buy rogaine foam singapore</a> Democratic Gov. Jerry Brown signed the bill in front of a cheering crowd of immigrants and their supporters, predicting other parts of the country will follow the example set by the nation's most populous state.

Bradley | September 01, 2015

I'm doing a masters in law <a href=" ">ventolin hfa 100 mcg salbutamol</a> The Republican-controlled House defeated its initial version of the farm bill, with $20 billion in food stamp cuts, because the cuts were too small to satisfy Tea Party-influenced conservatives. Democrats voted solidly against the cuts.

Sofia | September 01, 2015

I have my own business <a href=" ">where to buy rogaine foam in montreal</a> "Compared with non-drinkers with a shorter duration, non-drinkers with duration of 10 or more years between menarche and first pregnancy had 26% and 81% increased risk of breast cancer and proliferative BBD in our analysis respectively."

Gabriel | September 01, 2015

There's a three month trial period <a href=" ">bactrim tablets</a> Eaglen was among several think tank experts Pentagon brass invited to a meeting with defense officials to review of the document ahead of its release. Attendees of the on-background briefing said it was a candid and unprecedented exchange with their department counterparts to review the SCMR, which breaks down the financial woes embroiling the department.

Nelson | September 01, 2015

Canada>Canada <a href=" ">is it safe to use albuterol nebulizer while pregnant</a> NEW YORK, July 29 (Reuters) - Hudson's Bay Co saidon Monday it would buy Saks Inc in a $2.4 billion dealthat would add prime real estate to its portfolio and bring theluxury chain to its home market of Canada.

Garland | September 01, 2015

A few months <a href=" ">how much does zoloft cost in australia</a> She insisted that while she was "sure" Mr Miliband, who was a close ally of Mr Brown, was aware of the activities of the then prime minister's special adviser, it would not damage his position now.

Nicky | September 01, 2015

Recorded Delivery <a href=" ">flomax generic alternative</a> Joan Alker, executive director of the Center for Children and Families at the Georgetown University Health Policy Institute, said her center has written more than 100 pages of comments this year to influence new regulations. She recognizes that the administration has likely closed the door on tweaking rules.

Barton | September 01, 2015

i'm fine good work <a href=" ">long term use of paroxetine hydrochloride</a> And spectators ultimately ruled in Ellison's favor, partly because he brought the regatta, historically held miles out to sea, into San Francisco Bay where strolling tourists and die-hard sailing aficionados could watch the races up close.

Wally | September 01, 2015

Can I use your phone? <a href=" ">getting accutane</a> “I have always been a fan of country music, in fact I would have loved to do country music and sing country music earlier, but I was afraid being from New York that people wouldn’t be able to make that connection and think I was trying to be somebody that I wasn’t,” Panettiere continued. “But I have also taken a lot of my character from myself, my own personal life. No, I didn’t grow up in the country music industry or music industry, but I grew up a young female in the spotlight with a lot of the same stresses. A lot of the same pressures and dramas, and I definitely pulled a lot from my own life experience.”

Travis | September 01, 2015

I'm sorry, he's <a href=" ">tadacip della cipla</a> The researchers compared them to more than 1,600 typical teenagers in the same age range, measuring their autistic traits using a score called the Autism Spectrum Quotient (AQ), their "systemising" using the Systemising Quotient (SQ), and their empathy using the Empathy Quotient (EQ).

Harvey | September 03, 2015

I'm in a band <a href=" ">next day bimatoprost delivery</a> "We are much better than any other country in the region,but it is a temporary advantage," said Tuly Cooray, thesecretary-general of industry group Joint Apparel AssociationForum. "At the end of the day, the price is going to matter."

Wilber | September 03, 2015

I was made redundant two months ago <a href=" ">buy generic latisse cheap</a> "Painting and literature are two completely different languages," Gao, who lives in France, said at the show's recent opening. "Where literature reaches its limits of expressive power, that's where painting begins."

Morton | September 03, 2015

very best job <a href=" ">bimatoprost blue eyes</a> Castro had such an emotional attachment to the home that prosecutors said he broke down in tears when he had to sign over the property deed last week, saying it was wrong to tear it down because he had so many happy memories there.

Patric | September 03, 2015

Where's the nearest cash machine? <a href=" ">megalis 20 tablet online</a> But things look a little different now. The share sale attracted enormous interest, the kind not seen since the big privatisations of the Eighties, and in early, restricted trading the share price jumped by a third.

Alberto | September 03, 2015

Do you know what extension he's on? <a href=" ">generic salmeterol inhaler</a> "My kids are great they flourish at school," she wrote in response to a concerned mom's tweet. "They didn't get teased when step mom had a nip slip or went 2 rehab, it was 1 bad night."

Garland | September 03, 2015

Thanks for calling <a href=" ">purchase ezetimibe</a> Most of us think of ourselves as able communicators, but it is a mistake to simply assert "excellent communication" among your list of skills. Instead, take the time to be that excellent communicator by following these tips:

Walton | September 03, 2015

The United States <a href=" ">nizagara 50mg</a> Carlos Torres will start the finale here against the Nationals on Sunday. Jeremy Hefner will start the opener of a four-game set in Miami followed by Wheeler, Mejia and then Harvey in that series’ finale.

Harvey | September 03, 2015

How much does the job pay? <a href=" ">atarax 25 mg usage</a> "When money does get tight, I break down how much I can spend per day until I get paid," Turner says. "Knowing I have $20 or $30 per day, for example, helps me more than knowing I have $X per week or month."

Russel | September 03, 2015

I sing in a choir <a href=" ">cost of accutane privately uk</a> European shares are slated to track U.S. small gains onFriday. France's CAC 40 was seen up 0.2 percent whileGermany's Dax and Britain's FTSE were both seengaining 0.1 percent. U.S. share futures were down 0.1percent.

Connor | September 03, 2015

Through friends <a href=" ">m㸤icament estrace 1mg</a> While securitisation is now helping to transfer assets awayfrom unwilling holders, it also helped create the overhang.Pre-crisis, lending to non-traditional borrowers with poordocumentation, adverse credit or high LTVs was heavily relianton securitisation markets.

You? | October 07, 2015