diff --git a/README b/README
index da372ce..926f392 100644
--- a/README
+++ b/README
@@ -75,3 +75,6 @@ look at the file `blash.js' for a brief description of the fields of this object
or to the sample commands in `commands/' directory for seeing how to access
them.
+After creating your JSON file with the new command, don't forget to add the name
+of the command to the array `commands' in blash.json so that the CMS sees it.
+
diff --git a/blash.js b/blash.js
index 0db9bba..b2d1cce 100644
--- a/blash.js
+++ b/blash.js
@@ -137,50 +137,50 @@ function blash ()
{
this.cmdOut.innerHTML = this.json.shellName + ": command not found: " + cmd + '
';
}
+ }
- var value = this.prompt.value;
- var out = this.cmdOut.innerHTML;
+ var value = this.prompt.value;
+ var out = this.cmdOut.innerHTML;
- var text = ( shell.json.promptText ) ? shell.json.promptText : "[%n@%m %W] $ ";
- text = shell.unescapePrompt ( text, shell.json.promptSequences );
+ var text = ( shell.json.promptText ) ? shell.json.promptText : "[%n@%m %W] $ ";
+ text = shell.unescapePrompt ( text, shell.json.promptSequences );
- this.window.removeChild ( this.prompt );
- this.window.removeChild ( this.cmdOut );
+ this.window.removeChild ( this.prompt );
+ this.window.removeChild ( this.cmdOut );
- if ( this.__first_cmd )
+ if ( this.__first_cmd && this.prompt.value.length > 0 )
+ {
+ this.window.innerHTML += value + '
' + out + text;
+ this.__first_cmd = false;
+ } else {
+ if ( out )
{
- this.window.innerHTML += value + '
' + out + text;
- this.__first_cmd = false;
- } else {
- if ( out )
+ if ( out.match ( /^\s*\s*/ ))
{
- if ( out.match ( /^\s*\s*/ ))
- {
- out = '';
- }
+ out = '';
}
-
- this.window.innerHTML += value + '
' + out + text;
}
- this.prompt = document.createElement ( 'input' );
- this.prompt.setAttribute ( 'name', 'blashPrompt' );
- this.prompt.setAttribute ( 'type', 'text' );
- this.prompt.setAttribute ( 'class', 'promptInput' );
- this.prompt.setAttribute ( 'autocomplete', 'off' );
- this.prompt.setAttribute ( 'onkeydown', 'shell.getKey ( event )' );
- this.prompt.setAttribute ( 'onkeyup', 'this.focus()' );
- this.prompt.setAttribute ( 'onblur', 'return false' );
-
- this.cmdOut = document.createElement ( 'div' );
- this.cmdOut.setAttribute ( 'id', 'blashCmdOut' );
- this.cmdOut.setAttribute ( 'class', 'blashCmdOut' );
- this.cmdOut.innerHTML = '
';
-
- this.window.appendChild ( this.prompt );
- this.window.appendChild ( this.cmdOut );
- this.prompt.focus();
+ this.window.innerHTML += value + '
' + out + text;
}
+
+ this.prompt = document.createElement ( 'input' );
+ this.prompt.setAttribute ( 'name', 'blashPrompt' );
+ this.prompt.setAttribute ( 'type', 'text' );
+ this.prompt.setAttribute ( 'class', 'promptInput' );
+ this.prompt.setAttribute ( 'autocomplete', 'off' );
+ this.prompt.setAttribute ( 'onkeydown', 'shell.getKey ( event )' );
+ this.prompt.setAttribute ( 'onkeyup', 'this.focus()' );
+ this.prompt.setAttribute ( 'onblur', 'return false' );
+
+ this.cmdOut = document.createElement ( 'div' );
+ this.cmdOut.setAttribute ( 'id', 'blashCmdOut' );
+ this.cmdOut.setAttribute ( 'class', 'blashCmdOut' );
+ this.cmdOut.innerHTML = '
';
+
+ this.window.appendChild ( this.prompt );
+ this.window.appendChild ( this.cmdOut );
+ this.prompt.focus();
} else if ( key == 38 || key == 40 ) {
if ( key == 38 )
{
@@ -242,7 +242,66 @@ function blash ()
for ( var i in dirs )
{
- this.cmdOut.innerHTML += "
\n" + dirs[i].name;
+ if ( i > 0 )
+ {
+ this.cmdOut.innerHTML += "
\n";
+ }
+
+ this.cmdOut.innerHTML += dirs[i].name;
+ }
+
+ if ( dirs.length > 1 )
+ {
+ // Get the longest sequence in common
+ var sequences = new Array();
+ var min_len = 0;
+
+ for ( var i in dirs )
+ {
+ for ( var j in dirs )
+ {
+ if ( i != j )
+ {
+ if ( dirs[i].name.length != dirs[j].name.length )
+ {
+ min_len = ( dirs[i].name.length < dirs[j].name.length ) ? dirs[i].name.length : dirs[j].name.length;
+ } else {
+ min_len = dirs[i].name.length;
+ }
+
+ var k = 0;
+
+ for ( k = min_len-1; k >= 0; k-- )
+ {
+ if ( dirs[i].name.charAt ( k ) != dirs[j].name.charAt ( k ))
+ {
+ break;
+ }
+ }
+
+ var seq = '';
+
+ for ( var l=0; l < k; l++ )
+ {
+ seq += dirs[i].name.charAt ( l );
+ }
+
+ sequences.push ( seq );
+ }
+ }
+ }
+
+ var seq = sequences[0];
+
+ for ( var i in sequences )
+ {
+ if ( sequences[i].length < seq )
+ {
+ seq = sequences[i];
+ }
+ }
+
+ this.prompt.value = this.prompt.value.replace ( arg, seq + (( dirs[0].type == 'directory' ) ? '/' : '' ));
}
}
} else {
diff --git a/blash.json b/blash.json
index 37229d9..9fede53 100644
--- a/blash.json
+++ b/blash.json
@@ -51,27 +51,138 @@
"type" : "directory",
},
{
- "path" : "/home",
+ "path" : "/blog",
"type" : "directory",
},
{
- "path" : "/home/blacklight",
+ "path" : "/news",
"type" : "directory",
},
{
- "path" : "/home/blacklight/mbox",
- "type" : "file",
- "content" : "No new mail",
+ "path" : "/forum",
+ "type" : "directory",
+ },
+ {
+ "path" : "/tutorials",
+ "type" : "directory",
+ },
+ {
+ "path" : "/software",
+ "type" : "directory",
},
{
"path" : "/etc",
"type" : "directory",
},
{
- "path" : "/initrd",
+ "path" : "/home",
+ "type" : "directory",
+ },
+ {
+ "path" : "/home/guest",
+ "type" : "directory",
+ },
+ {
+ "path" : "/home/guest/mbox",
+ "type" : "file",
+ "content" : "No new mail",
+ },
+ {
+ "path" : "/google",
"type" : "file",
"href" : "http://www.google.com",
},
+ {
+ "path" : "/blog/post1",
+ "type" : "file",
+ "content" : "This is my first post",
+ },
+ {
+ "path" : "/blog/post2",
+ "type" : "file",
+ "content" : "This is my second post",
+ },
+ {
+ "path" : "/blog/post3",
+ "type" : "file",
+ "content" : "This is my third post",
+ },
+ {
+ "path" : "/etc/blashrc",
+ "type" : "file",
+ "content" : "This is the default blash configuration file",
+ },
+ {
+ "path" : "/forum/post1",
+ "type" : "file",
+ "content" : "Sent by admin at 00:00:01
Welcome to the forum
\n" +
+ "Sent by troll at 00:00:02
lulz
\n",
+ },
+ {
+ "path" : "/forum/post2",
+ "type" : "file",
+ "content" : "Sent by lolcat at 00:00:03
Can I haz cheezburger?
\n",
+ },
+ {
+ "path" : "/home/guest/.blashrc",
+ "type" : "file",
+ "content" : "Custom blash configuration file",
+ },
+ {
+ "path" : "/home/guest/mbox",
+ "type" : "file",
+ "content" : "No new mail",
+ },
+ {
+ "path" : "/news/news1",
+ "type" : "file",
+ "content" : "Nothing new under the sun",
+ },
+ {
+ "path" : "/software/soft1",
+ "type" : "file",
+ "href" : "/software/soft1.tar.gz",
+ },
+ {
+ "path" : "/software/soft2",
+ "type" : "file",
+ "href" : "/software/soft2.tar.gz",
+ },
+ {
+ "path" : "/software/soft3",
+ "type" : "file",
+ "href" : "/software/soft3.tar.gz",
+ },
+ {
+ "path" : "/tutorials/tut1",
+ "type" : "file",
+ "href" : "/software/tut1.pdf",
+ },
+ {
+ "path" : "/tutorials/tut2",
+ "type" : "file",
+ "href" : "/software/tut2.pdf",
+ },
+ {
+ "path" : "/github",
+ "type" : "file",
+ "href" : "https://github.com/BlackLight/blash",
+ },
+ {
+ "path" : "/aboutme",
+ "type" : "file",
+ "content" : "Luke, I am your father",
+ },
+ {
+ "path" : "/contacts",
+ "type" : "file",
+ "content" : "Contact me at spam@montypython.com",
+ },
+ {
+ "path" : "/irc",
+ "type" : "file",
+ "content" : "IRC channel at #thegame@irc.randomstuff.com",
+ },
],
"commands" : [
diff --git a/commands/find.json b/commands/find.json
index 4f1a2a5..596b6fd 100644
--- a/commands/find.json
+++ b/commands/find.json
@@ -20,7 +20,7 @@
arg = RegExp.$1;
}
- var re = new RegExp ( arg );
+ var re = new RegExp ( arg, "i" );
for ( var i in shell.json.directories )
{