Adding find and whoami commands
This commit is contained in:
parent
25c03b8caf
commit
3050d092e7
6 changed files with 111 additions and 4 deletions
10
blash.css
10
blash.css
|
@ -13,6 +13,7 @@ input.promptInput
|
|||
color : #888;
|
||||
font-family : Terminus, courier, monospace, fixed;
|
||||
font-size : 13px;
|
||||
width : 400px;
|
||||
}
|
||||
|
||||
div#blashWindow
|
||||
|
@ -35,9 +36,14 @@ span.directory
|
|||
color : #2553ee;
|
||||
}
|
||||
|
||||
.file
|
||||
a
|
||||
{
|
||||
color : #4f4;
|
||||
color : green;
|
||||
}
|
||||
|
||||
a:visited
|
||||
{
|
||||
color : green;
|
||||
}
|
||||
|
||||
span.syntax
|
||||
|
|
20
blash.js
20
blash.js
|
@ -35,6 +35,9 @@ function blash ()
|
|||
|
||||
/** Counter of the open <span> tags when replacing the colours in the command prompt */
|
||||
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 )
|
||||
|
@ -133,7 +136,22 @@ function blash ()
|
|||
|
||||
this.window.removeChild ( this.prompt );
|
||||
this.window.removeChild ( this.cmdOut );
|
||||
this.window.innerHTML += value + '<br/>' + out + text;
|
||||
|
||||
if ( this.__first_cmd )
|
||||
{
|
||||
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.setAttribute ( 'name', 'blashPrompt' );
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"extent permitted by law.<br/>" +
|
||||
"Type '<span class=\"brief\">man blash</span>' for help on usage and available commands<br/><br/>",
|
||||
|
||||
"user" : "blacklight",
|
||||
"user" : "guest",
|
||||
"machine" : "localhost",
|
||||
"shellName" : "blash",
|
||||
"basepath" : "/",
|
||||
|
@ -54,6 +54,7 @@
|
|||
{
|
||||
"path" : "/home/blacklight/mbox",
|
||||
"type" : "file",
|
||||
"content" : "No new mail",
|
||||
},
|
||||
{
|
||||
"path" : "/etc",
|
||||
|
@ -69,9 +70,11 @@
|
|||
"commands" : [
|
||||
"cat",
|
||||
"cd",
|
||||
"find",
|
||||
"ls",
|
||||
"man",
|
||||
"pwd",
|
||||
"whoami",
|
||||
],
|
||||
}
|
||||
|
||||
|
|
48
commands/find.json
Normal file
48
commands/find.json
Normal file
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"name" : "find",
|
||||
|
||||
"info" : {
|
||||
"syntax" : "find <text|regex>",
|
||||
"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;
|
||||
},
|
||||
}
|
||||
|
|
@ -114,6 +114,17 @@
|
|||
|
||||
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;
|
||||
|
||||
if ( arg.match ( /^\// ))
|
||||
|
|
21
commands/whoami.json
Normal file
21
commands/whoami.json
Normal 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";
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in a new issue