grep command

This commit is contained in:
BlackLight 2010-12-30 03:27:26 +01:00
parent 4065711818
commit 06177085f9
6 changed files with 119 additions and 5 deletions

View file

@ -66,3 +66,18 @@ span.brief
color : green; color : green;
} }
span.filematch
{
color : #672377;
}
span.linematch
{
color : #73d216;
}
span.match
{
color : #992010;
}

View file

@ -49,6 +49,29 @@
if ( http2.readyState == 4 && http2.status == 200 ) if ( http2.readyState == 4 && http2.status == 200 )
{ {
shell.files = eval ( '(' + http2.responseText + ')' ); shell.files = eval ( '(' + http2.responseText + ')' );
// Remove duplicates
var tmp = new Array();
for ( var i in shell.files )
{
var contains = false;
for ( var j=0; j < tmp.length && !contains; j++ )
{
if ( shell.files[i].path == tmp[j].path )
{
contains = true;
}
}
if ( !contains )
{
tmp.push ( shell.files[i] );
}
}
shell.files = tmp;
} }
} }

View file

@ -81,6 +81,29 @@
if ( http2.readyState == 4 && http2.status == 200 ) if ( http2.readyState == 4 && http2.status == 200 )
{ {
shell.files = eval ( '(' + http2.responseText + ')' ); shell.files = eval ( '(' + http2.responseText + ')' );
// Remove duplicates
var tmp = new Array();
for ( var i in shell.files )
{
var contains = false;
for ( var j=0; j < tmp.length && !contains; j++ )
{
if ( shell.files[i].path == tmp[j].path )
{
contains = true;
}
}
if ( !contains )
{
tmp.push ( shell.files[i] );
}
}
shell.files = tmp;
} }
} }

View file

@ -184,6 +184,29 @@ function blash ()
if ( http2.readyState == 4 && http2.status == 200 ) if ( http2.readyState == 4 && http2.status == 200 )
{ {
shell.files = eval ( '(' + http2.responseText + ')' ); shell.files = eval ( '(' + http2.responseText + ')' );
// Remove duplicates
var tmp = new Array();
for ( var i in shell.files )
{
var contains = false;
for ( var j=0; j < tmp.length && !contains; j++ )
{
if ( shell.files[i].path == tmp[j].path )
{
contains = true;
}
}
if ( !contains )
{
tmp.push ( shell.files[i] );
}
}
shell.files = tmp;
} }
} }
@ -618,8 +641,21 @@ function blash ()
return prompt; return prompt;
} }
/**
* \brief Expand an argument as path, transforming it into an absolute path, removing extra slashes and expanding '..' notations
*/
this.expandPath = function ( arg ) this.expandPath = function ( arg )
{ {
if ( !arg || arg.length == 0 )
{
return false;
}
while ( arg.match ( /(^|\/)\.\// ))
{
arg = arg.replace ( /(^|\/)\.\//, '/' );
}
if ( arg.match ( /^[^\/]/ )) if ( arg.match ( /^[^\/]/ ))
{ {
arg = this.path + '/' + arg; arg = this.path + '/' + arg;
@ -656,5 +692,26 @@ function blash ()
return arg; return arg;
} }
/**
* \brief Expand the star '*' notations inside of a path
*/
this.expandStar = function ( arg )
{
arg = arg.replace ( /([^\\])?\*/g, '$1.*' );
var matches = new Array();
var re = new RegExp ( arg );
for ( var i=0; i < this.files.length; i++ )
{
if ( this.files[i].path.match ( re ))
{
matches.push ( this.files[i] );
}
}
return matches;
}
} }

View file

@ -59,6 +59,7 @@
"echo", "echo",
"eval", "eval",
"find", "find",
"grep",
"logout", "logout",
"ls", "ls",
"man", "man",

View file

@ -96,11 +96,6 @@ $files_json = <<<JSON
"type" : "file", "type" : "file",
"content" : "Custom blash configuration file" "content" : "Custom blash configuration file"
}, },
{
"path" : "/home/guest/mbox",
"type" : "file",
"content" : "No new mail"
},
{ {
"path" : "/news/news1", "path" : "/news/news1",
"type" : "file", "type" : "file",