What should a Ruby shell look like?
metacircus.com
metacircus.com
IPython worked it's way into my workflow because I wanted a richer "real language" REPL, and now I end up using its shell capabilities sometimes. If I had started out trying to use it as a shell it would have failed at that miserably, even though it's the best implementation I know of.
And 15 years later, I still don't use it.
The shell really is easier to use on a daily basis than most scripting languages (and yes, this does include Perl). Yes, I could type 'ls <enter>' and get a directory listing. But what about of a different directory? In a shell, it's 'ls /tmp' (for example). I want to see if a particular email got delivered? 'grep 70333248A03 /var/log/mail.log'.
Unless the scripting language makes it this trivial to issue simple commands, you probably won't be using it as a shell for very long.
At first, I just wanted a self-contained, cross-platform ruby shell, that I could pop open from any computer without having to (or being able to) install anything (with rubyscript2exe in case there was no Ruby around.)
Then, I started adding all sorts of neat convenience methods. I sort of wanted to imitate Powershell, but then I started wanting even more. Basically, I was going to implement a version of Plan 9, but with an Object system instead of a filesystem. I wrote up a user story that went like this:
~$ self
=> #<Home @user=#<User ...>>
~$ x = "hello"
=> "hello"
~$ ls
=> x
~$ cd x
~/x$ ls
class -> /lib/String
methods/
~/x$ cd methods
~/x/methods$ ls
capitalize
chomp
downcase
[etc]
~/x/methods$ ./capitalize
=> "Hello"
~/x/methods$ cd capitalize; ls class
class -> /lib/Method
~/x/methods/capitalize$ cd !; ls
class -> /lib/String
methods/
~/x/methods/capitalize/!$ inspect # ./methods is first in /etc/path
=> "Hello"
It got even more complex from there, where entering an executor (a !/ directory) of a method with parameters would put you in a closure, that you had to then curry by putting new objects into each successive directory... I sort of gave up when I saw how obtuse the syntax was. It was sort of like LISP, but with paths instead of linked lists. :)This seems like fun anyway. Operator overloading could go a long way in providing a bash-like syntax, while still providing Ruby-like extensibility.
abstraction is a form of memory.
Second: I think where this will really shine is in the "twilight zone" of shell scripting. So often, I start off with a short chain of commands on the command prompt. I'll keep adding to the chain, until at some point I feel the need to move this elaborate chain (usually an alias at that point) into it's own script file. I could copy directly, but then any improvements would require continuing to use shell script (ugh). On the other hand, I could translate the existing script to Ruby, but then I'd have to put in the overhead to do the translation with no immediate gain.
With this, I could see doing a direct copy-->paste from command line to script file and just keep going...or better yet, since it's all Ruby, why not an extension on File to automatically write out X lines of history to a script file?
...oooooh! I'm excited already!
This one (Rubish) looks a bit half baked, but I'll have to look into it some more.