blash/commands/find.json
2010-12-24 19:09:37 +01:00

48 lines
880 B
JSON

{
"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, "i" );
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;
},
}