I was about to suggest you could do this easily in Ruby, but it turns out that getting a catch-all method_missing at the top level to work is quite annoying - too many things in both Irb and Pry (the two main Ruby REPLs) seem to rely on trying method calls and catching the exceptions in ways that broke horribly with my most naive attempts.
But something like this works of-sorts in Ruby:
module Sh
def method_missing sym, *args
bin = ENV["PATH"].split(":").collect do |path|
full = File.join(path,sym.to_s)
File.exists?(full) ? full : nil
end.compact[0] rescue nil
if !bin
raise NameError.new(sym.to_s)
else
bin = system(bin,*args.collect{|a| a.to_s})
end
end
end
self.extend Sh
Pry can't handle it very well, probably as it relies extensively on method_missing "magic" itself, but Irb seems do do fine with it.
I'm sure there are ways to do the above in much cleaner ways, and even in Ruby syntax still gets in the way. E.g. you need to do 'ps :aux' or 'ps "aux"' instead of "ps aux" or the options will get interpreted as a method (though you could conceivably try to handle that by capturing NameError exceptions and applying really horribly nasty hacks, there would be a special place in hell for you if you were to do that; even the above is likely to break all kinds of stuff).
> And what if the shell output wasn't line-oriented but a live hypertext doc, say HTML5?
There have been all kinds of attempts at that, notably XmlTerm from Mozilla ca. 2000 [1]. It turns out to be a hard problem to get it right enough to make people use it. Basically to get that working at all I suspect you need to start with a good terminal emulator + a good shell, and make small enhancements rather than go the other way which most of these kind of projects have done.
But something like this works of-sorts in Ruby:
Pry can't handle it very well, probably as it relies extensively on method_missing "magic" itself, but Irb seems do do fine with it.I'm sure there are ways to do the above in much cleaner ways, and even in Ruby syntax still gets in the way. E.g. you need to do 'ps :aux' or 'ps "aux"' instead of "ps aux" or the options will get interpreted as a method (though you could conceivably try to handle that by capturing NameError exceptions and applying really horribly nasty hacks, there would be a special place in hell for you if you were to do that; even the above is likely to break all kinds of stuff).
> And what if the shell output wasn't line-oriented but a live hypertext doc, say HTML5?
There have been all kinds of attempts at that, notably XmlTerm from Mozilla ca. 2000 [1]. It turns out to be a hard problem to get it right enough to make people use it. Basically to get that working at all I suspect you need to start with a good terminal emulator + a good shell, and make small enhancements rather than go the other way which most of these kind of projects have done.
[1] http://www.xml.com/pub/a/2000/06/07/xmlterm/index.html