blash/commands/cat.json

58 lines
1.2 KiB
JSON

{
"name" : "cat",
"info" : {
"syntax" : "cat <file>",
"brief" : "Show the content of a page",
},
"action" : function ( arg )
{
var out = '';
var found = false;
var dir = shell.files;
if ( !arg || arg.length == 0 )
{
return "Argument required<br/>\n";
}
arg = shell.expandPath ( arg );
for ( var i=0; i < dir.length && !found; i++ )
{
if ( dir[i].path == arg )
{
found = true;
if ( dir[i].type == 'directory' )
{
return "cat: " + dir[i].path + ": Is a directory<br/>\n";
} else {
if ( dir[i].href )
{
window.open ( dir[i].href );
} else if ( dir[i].link_to && dir[i].link_to.length > 0 ) {
return this.action ( dir[i].link_to );
} else if ( dir[i].content ) {
var replaced=dir[i].content.replace(/(https?:\/\/(www\.)?[0-9a-zA-Z-_\.\/:]*)/g, "<a href='$1'>$1</a>");
replaced = replaced.replace(".'>", "'>");
replaced = replaced.replace(".</a>", "</a>.");
return "<pre>"+replaced+"</pre>";
}
}
}
}
if ( !found )
{
arg = arg.replace ( '<', '&lt;' );
arg = arg.replace ( '>', '&gt;' );
return "cat: " + arg + ": No such file or directory<br/>\n";
}
out = out.replace ( /<br\/?>\s*$/, '' );
return out;
}
}