Adding find and whoami commands

This commit is contained in:
BlackLight 2010-12-23 15:45:53 +01:00
parent 25c03b8caf
commit 3050d092e7
6 changed files with 111 additions and 4 deletions

View file

@ -13,6 +13,7 @@ input.promptInput
color : #888; color : #888;
font-family : Terminus, courier, monospace, fixed; font-family : Terminus, courier, monospace, fixed;
font-size : 13px; font-size : 13px;
width : 400px;
} }
div#blashWindow div#blashWindow
@ -35,9 +36,14 @@ span.directory
color : #2553ee; color : #2553ee;
} }
.file a
{ {
color : #4f4; color : green;
}
a:visited
{
color : green;
} }
span.syntax span.syntax

View file

@ -35,6 +35,9 @@ function blash ()
/** Counter of the open <span> tags when replacing the colours in the command prompt */ /** Counter of the open <span> tags when replacing the colours in the command prompt */
this.__open_spans = 0; this.__open_spans = 0;
/** Check if this is the first command given in this session (for fixing <br/> stuff) */
this.__first_cmd = true;
/**************************************/ /**************************************/
this.loadCommand = function ( cmd ) this.loadCommand = function ( cmd )
@ -133,7 +136,22 @@ function blash ()
this.window.removeChild ( this.prompt ); this.window.removeChild ( this.prompt );
this.window.removeChild ( this.cmdOut ); this.window.removeChild ( this.cmdOut );
if ( this.__first_cmd )
{
this.window.innerHTML += value + '<br/>' + out + text; this.window.innerHTML += value + '<br/>' + out + text;
this.__first_cmd = false;
} else {
if ( out )
{
if ( out.match ( /^\s*<br.?>\s*/ ))
{
out = '';
}
}
this.window.innerHTML += value + '<br/>' + out + text;
}
this.prompt = document.createElement ( 'input' ); this.prompt = document.createElement ( 'input' );
this.prompt.setAttribute ( 'name', 'blashPrompt' ); this.prompt.setAttribute ( 'name', 'blashPrompt' );

View file

@ -9,7 +9,7 @@
"extent permitted by law.<br/>" + "extent permitted by law.<br/>" +
"Type '<span class=\"brief\">man blash</span>' for help on usage and available commands<br/><br/>", "Type '<span class=\"brief\">man blash</span>' for help on usage and available commands<br/><br/>",
"user" : "blacklight", "user" : "guest",
"machine" : "localhost", "machine" : "localhost",
"shellName" : "blash", "shellName" : "blash",
"basepath" : "/", "basepath" : "/",
@ -54,6 +54,7 @@
{ {
"path" : "/home/blacklight/mbox", "path" : "/home/blacklight/mbox",
"type" : "file", "type" : "file",
"content" : "No new mail",
}, },
{ {
"path" : "/etc", "path" : "/etc",
@ -69,9 +70,11 @@
"commands" : [ "commands" : [
"cat", "cat",
"cd", "cd",
"find",
"ls", "ls",
"man", "man",
"pwd", "pwd",
"whoami",
], ],
} }

48
commands/find.json Normal file
View file

@ -0,0 +1,48 @@
{
"name" : "find",
"info" : {
"syntax" : "find &lt;text|regex&gt;",
"brief" : "Search for file or directories in the root hierarchy",
},
"action" : function ( arg )
{
var out = '';
if ( !arg || arg.length == 0 )
{
return "Argument required<br/>\n";
}
if ( arg.match ( "^['\"](.*)['\"]$" ))
{
arg = RegExp.$1;
}
var re = new RegExp ( arg );
for ( var i in shell.json.directories )
{
var dir = shell.json.directories[i];
if ( dir.path.match ( re ))
{
if ( dir.type == 'directory' )
{
out += '<span class="directory">' + dir.path + "</span><br/>\n";
} else if ( dir.type == 'file' && dir.href ) {
out += '<span class="file">' +
'<a href="' + dir.href + '" target="_new">' +
dir.path + "</a></span><br/>\n";
} else {
out += dir.path + "<br/>\n";
}
}
}
return out;
},
}

View file

@ -114,6 +114,17 @@
if ( !exists ) if ( !exists )
{ {
for ( var i=0; i < shell.json.directories.length; i++ )
{
var dir = shell.json.directories[i];
arg = arg.replace ( /\/+$/, '' );
if ( dir.path.match ( arg ))
{
return '';
}
}
var re = null; var re = null;
if ( arg.match ( /^\// )) if ( arg.match ( /^\// ))

21
commands/whoami.json Normal file
View file

@ -0,0 +1,21 @@
{
"name" : "whoami",
"info" : {
"syntax" : "whoami",
"brief" : "Print effective userid",
},
"action" : function ( arg )
{
var out = '';
if ( arg )
{
return "whoami: extra operand `" + arg + "'<br/>\n";
}
return shell.json.user + "<br/>\n";
},
}