The Artima Developer Community
Sponsored Link

Java Buzz Forum
grash: a unix-like shell for your JVM

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
Jeremy Rayner

Posts: 111
Nickname: j6wbs
Registered: Sep, 2003

jez codes stuff
grash: a unix-like shell for your JVM Posted: Oct 25, 2004 9:36 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Jeremy Rayner.
Original Post: grash: a unix-like shell for your JVM
Feed Title: javanicus
Feed URL: http://www.javanicus.com/blog2/subjects/java-rss.xml
Feed Description: Jeremy Rayner on java and other stuff.
Latest Java Buzz Posts
Latest Java Buzz Posts by Jeremy Rayner
Latest Posts From javanicus

Advertisement
"If everything in Unix is a file and everything in Java is an Object, wouldn't it be nice if you could explore your Objects in the JVM with the same powerful mechanisms you use in Unix."

My line of thought a couple of weeks ago has led to a small implementation of a shell for the JVM, which I have named grash. The name is derived from the fact that it is based in part on the externally observed behaviour of the bash shell, and that it is written in and exposes to the user the Groovy programming language. Hence 'GRoovy-Again SHell'

Using the concept of a 'current working instance' in place of a 'current working directory' some of the tools in a normal shell already make some sense.

what follows has been adapted from the wonderful Kernighan and Pike

What Objects are out there?

The ls command lists the names (not contents) of Objects:

/ grash$ ls
junk
main
temp                
/ grash$
The names are sorted into alphabetical order automatically.ls , like most commands, has options that may be used to alter its default behavior. The -l option gives a "long" listing that provides more information about each Object:
/ grash$ ls 
-------rw-  junk
--------x  main
------rw-  temp
/ grash$
The string - - - - - - r w - tells who has permission to read and write the Object; in this case there is a public getter and setter for the junk and temp objects.

Printing Objects - cat

Now that you have some Objects, how do you look at their contents? The simplest of all the printing commands is cat . cat prints the contents of the Object name by its argument:
/ grash$ cat junk
To be or not to be
/ grash$ cat temp
That is the question.
/ grash$

A handful of useful methods

Grash exposes the Java and Groovy Libraries to the command line user, providing
/ grash$ cat junk
To be or not to be
/ grash$ cat junk.length()
18
/ grash$ cat junk.tokenize()
[To, be, or, not, to, be]
/ grash$ cat junk.tokenize().sort()
[To, be, be, not, or, to]
/ grash$

Pipes

A pipe is a way to connect the output of one expression to the input of another. I have implemented pipelines in the simplest way at the moment.
/ grash$ ls -a | println size()
11
/ grash$
The expressions in a pipeline currently evaluate one after another, but in order to behave like Unix, concurrent evaluation of the commands in a pipeline would be desired.

The methods are currently called on the result of the previous evaluation, again this should perhaps be a different mechanism, using the current working instance and others.

NOTES

How do I embed grash in my own programs

  • put grash.jar in your classpath
  • include these lines somewhere in your code (note: you can pass your own input/output streams in the Grash constructor}
import com.javanicus.grash.Grash;
...
Grash grash = new Grash(myObject);
Thread consoleThread = new Thread(grash);
consoleThread.start();

Under the covers

  • 100% Groovy source, at the moment (although some unit tests on Java will be needed)
  • Object references are currently piped around, rather than streams.
  • The grash command line parser takes precedence over groovy, so any ; | > & symbol will be ignored by the time that groovy sees it.

What's left to do...

  • Everything...
  • I have implemented other features such as cd , ps , pipes, redirects and some advanced options on ls
    • Feel free to play with them.
  • Decisions over pipes:
    • object handles or serialized objects ?
    • Do the methods in the subsequent pipe commands call methods on the result of the former, or methods on the 'current working instance' ?

HEALTH WARNINGS

  • This project is just a baby (born 14 Oct 2004), and is an extrapolation from the concept of file/object equivalence.
  • This project uses Groovy which is still in Beta.
  • grash.jar contains all of groovy-all.jar, to help ease of setup. However a version without included groovy will be available upon request.
  • You won't be able to get STDIN (InputStream) to work if you are running your program from ant and it's derivates.

BIG DISCLAIMERS

  • "It's amazing what you can do when you're too stupid to realised that it is impossible to achieve"
  • I have no clue whether this will be useful, I'm just experimenting right now.

I'm looking forward to your comments and ideas

Read: grash: a unix-like shell for your JVM

Topic: RE: WS-* and the big picture Previous Topic   Next Topic Topic: IM Fat Chewing, vol. III: Etymology of


Sponsored Links



Google
  Web Artima.com   

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