{ "banner" : "blash version 0.1
" + "Copyright (C) 2010 BlackLight <blacklight@autistici.org>" + "
Licence GPLv3+: GNU GPL version 3 or later " + "<" + "http://gnu.org/licences/gpl.html>

" + "This is free software; you are free to change and " + "redistribuite it.
There is NO WARRANTY, to the " + "extent permitted by law.
" + "Type 'man blash' for help on usage and available commands

", "user" : "blacklight", "machine" : "localhost", "shellName" : "blash", "basepath" : "/", "promptText" : "[#{800}%n#{888}@#{800}%m#{888} %W] $ ", "promptSequences" : [ { "sequence" : "%n", "default_text" : "blacklight", "text" : function () { return shell.json.user; }, }, { "sequence" : "%m", "default_text" : "localhost", "text" : function () { return shell.json.machine; }, }, { "sequence" : "%W", "default_text" : "~", "text" : function () { return shell.json.basepath; }, } ], "directories" : [ { "path" : "/", "type" : "directory", }, { "path" : "/home", "type" : "directory", }, { "path" : "/home/blacklight", "type" : "directory", }, { "path" : "/etc", "type" : "directory", }, { "path" : "/initrd", "type" : "file", "href" : "http://www.google.com", }, ], "commands" : [ { "name" : "pwd", "info" : { "syntax" : "pwd", "brief" : "Print name of current/working directory", }, "action" : function ( arg ) { if ( arg ) { if ( arg.length > 0 ) { return this.name + ": Too many arguments
"; } else { return shell.path + '
'; } } else { return shell.path + '
'; } }, }, { "name" : "clear", "info" : { "syntax" : "clear", "brief" : "Clear the terminal screen", }, "action" : function ( arg ) { var out = ''; shell.window.innerHTML = '' + '' + ''; return out; }, }, { "name" : "man", "info" : { "syntax" : "man <page>", "brief" : "Display the manual page for the command 'page'", }, "action" : function ( arg ) { var out = ''; if ( arg == undefined || arg.length == 0 ) { return "What manual page do you want?
\n"; } var cmd = shell.json.commands; if ( arg == 'blash' ) { var commands = new Array(); out = 'Type "man <command>" for a more detailed help on these commands

'; for ( var i=0; i < cmd.length; i++ ) { commands.push ( cmd[i].info.syntax ); } commands.sort(); for ( var i in commands ) { out += '' + commands[i] + '
'; } return out; } var found = false; for ( var i=0; i < cmd.length && !found; i++ ) { if ( arg == cmd[i].name ) { if ( cmd[i].info.syntax.length > 0 && cmd[i].info.brief.length > 0 ) { found = true; out = '' + cmd[i].info.syntax + '

' + '' + cmd[i].info.brief + '
'; } } } if ( !found ) { return "No manual entry for " + arg + "
\n"; } return out; }, }, { "name" : "ls", "info" : { "syntax" : "ls [path]", "brief" : "List directory contents", }, "action" : function ( arg ) { var dirs = new Array(); var out = ''; var exists = false; if ( !arg || arg.length == 0 ) { var re = new RegExp ( '^' + shell.path + '[^/]+$' ); } else if ( arg && arg.length > 0 ) { var re = null; if ( arg.match ( /^\// )) { re = new RegExp ( '^' + arg + '/[^/]+$' ); } else { re = new RegExp ( '^' + shell.path + (( shell.path == '/' ) ? '' : '/' ) + arg + '/[^/]+$' ); } } for ( var i=0; i < shell.json.directories.length; i++ ) { var dir = shell.json.directories[i]; if ( dir.path.match ( re )) { exists = true; dir.path.match ( /\/([^\/]+)$/ ); dirs.push ({ "path" : RegExp.$1, "type" : dir.type, "href" : dir.href, }); } } if ( dirs.length > 0 ) { var ordered = false; // Directories go first while ( !ordered ) { ordered = true; for ( var i=0; i < dirs.length-1; i++ ) { for ( var j=i+1; j < dirs.length; j++ ) { if ( dirs[i].type == 'file' && dirs[j].type == 'directory' ) { var tmp = dirs[i]; dirs[i] = dirs[j]; dirs[j] = tmp; ordered = false; } } } } ordered = false; // Sort the names while ( !ordered ) { ordered = true; for ( var i=0; i < dirs.length-1; i++ ) { for ( var j=i+1; j < dirs.length; j++ ) { if ( dirs[i].type == dirs[j].type && dirs[i].path > dirs[j].path ) { var tmp = dirs[i]; dirs[i] = dirs[j]; dirs[j] = tmp; ordered = false; } } } } for ( var i in dirs ) { if ( dirs[i] ) { if ( dirs[i].path.length > 0 ) { if ( dirs[i].type == 'directory' ) { out += '' + dirs[i].path + '/
'; } else { if ( dirs[i].href && dirs[i].href.length > 0 ) { out += '' + dirs[i].path + '*
'; } else { out += '' + dirs[i].path + '
'; } } } } } } if ( !exists ) { var re = null; if ( arg.match ( /^\// )) { re = new RegExp ( '^' + arg ); } else { re = new RegExp ( '^' + shell.path + (( shell.path == '/' ) ? '' : '/' ) + arg ); } for ( var i=0; i < shell.json.directories.length; i++ ) { var dir = shell.json.directories[i]; if ( dir.path.match ( re )) { exists = true; break; } } if ( !exists ) { out = this.name + ": cannot access " + arg + ": No such file or directory
"; } else { out = ''; } } return out; } } ], }