Javascript login shell

All timestamps are based on your local time of:

Posted by: stak
Tags: mozilla
Posted on: 2014-03-23 10:46:29

I was playing around with node.js this weekend, and I realized that it's not that hard to end up with a Javascript-based login shell. A basic one can be obtained by simply installing node.js and ShellJS on top of it. Add CoffeeScript to get a slightly less verbose syntax. For example:

kats@kgupta-pc shelljs$ coffee
coffee> require './global.js'
coffee> ls()
  'test' ]
coffee> cat 'global.js'
'var shell = require(\'./shell.js\');\nfor (var cmd in shell)\n  global[cmd] = shell[cmd];\n'
coffee> cp('global.js', 'foo.tmp')
coffee> cat 'foo.tmp'
'var shell = require(\'./shell.js\');\nfor (var cmd in shell)\n  global[cmd] = shell[cmd];\n'
coffee> rm 'foo.tmp'

Basically, if you're in a JS REPL (node.js or coffee) and you have access to functions that wrap shell utilities (which is what ShellJS provides some of) then you can use that setup as your login shell instead of bash or zsh or whatever else you might be using.

I'm a big fan of bash but I am sometimes frustrated with some things in it, such as hard-to-use variable manipulation and the fact that loops sometimes create subshells and make state manipulation hard. Being able to write scripts in JS instead of bash would solve that quite nicely. There are probably other use cases in which having a JS shell as your login shell would be quite handy.

Posted by Neil Munro at 2014-03-23 12:58:29
I had been looking into this idea myself, although admittedly had not gotten very far with it, I dubbed the idea JaSh (Javascript Shell, obviously) and experimented with various things, I feel that the prototypical nature of JavaScript affords a wonderful shell environment as one if able to freely alter the commands and properties at will.

If you were to work on this project I'd certainly use it, I'd be more than happy to do some testing too!

[ Reply to this ]
Allowed expansions in comments/replies: [i]italic[/i], [u]underline[/u], [b]bold[/b], [code]code[/code], [sub]subscript[/sub], [sup]superscript[/sup], [url=http://some.url]linked text[/url]
Human verification: Sum of twenty and forty-one =
(c) Kartikaya Gupta, 2004-2015. User comments owned by their respective posters. All rights reserved.
You are accessing this website via IPv4. Consider upgrading to IPv6!