A very, very limited implementation of /bin/sh
, in javascript.
Acts like a unix shell in your browser, backed by a JSON filesystem.
Comes without coreutils.
var fs = { /* filesystem tree, see below */ };
var env = {
HOME: '/home/leif',
PATH: '/bin', /* '/bin:/usr/bin' is also okay */
USER: 'leif',
HOSTNAME: 'github'
};
var motd = [
'hello world'
];
var output = $('#output');
var prompt = $('#prompt);
var input = $('#input');
new Term(fs, env, output, prompt, input);
for (var i in motd) {
term.println(motd[i]);
}
The Term
constructor takes five arguments:
-
fs
: The filesystem the shell should present to the user. This is a nested javascript object hierarchy faking a filesystem.Each node should have at least a
type
(ofTerm.types.dir
,Term.types.file
, orTerm.types.link
) and aperm
, which is a sum (or OR) ofTerm.perms.read
,Term.perms.write
, andTerm.perms.exec
. I don't expect to seeTerm.perms.write
here, but hey, maybe you want it.If something has
Term.perms.read
, it should havecontents
. A file should have an array of strings, and a directory should have more nodes underneath it. A link should also have an array, but it should only have one element, the string the link should point to. Links, when printed, be printed in<a>
elements, using theTerm.show
function.If something has
Term.perms.exec
, it should have anexec
function. This will be called with the strings given on the command line, minus the command's name (noargv[0]
). It's not yet smart enough to parse\
or quoted strings; it literally just passes the result ofString.split(' ')
, minus empty strings. Additionally, inside yourexec
function, thethis
reference will refer to theTerm
object from which it was called. There are several helpful functions within that you are free to use. -
env
: A javascript object with at leastHOME
,PATH
,USER
, andHOSTNAME
fields, and optionallyPWD
(which defaults toenv['HOME']
). These should be self-explanatory if you're reading this. -
output
,prompt
, andinput
: DOM elements used for outputting, prompting, and inputting.
You will have to implement your own coreutils inside your filesystem hierarchy.
Yes. Email me ([email protected]).
Fork and send pull requests.