Tab completion and ls/cd commands improved

This commit is contained in:
BlackLight 2010-12-23 01:28:38 +01:00
parent 12e9512136
commit e6e55ab6fd
4 changed files with 41 additions and 18 deletions

View file

@ -128,16 +128,20 @@ function blash ()
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 );
this.window.removeChild ( this.prompt );
this.window.removeChild ( this.cmdOut );
this.window.innerHTML += value + '<br/>' + out + this.promptText.innerHTML;
this.window.innerHTML += value + '<br/>' + 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 ( 'onkeyup', 'shell.getKey ( event )' );
this.prompt.setAttribute ( 'onkeydown', 'shell.getKey ( event )' );
this.prompt.setAttribute ( 'onkeyup', 'this.focus()' );
this.cmdOut = document.createElement ( 'div' );
this.cmdOut.setAttribute ( 'id', 'blashCmdOut' );
@ -175,6 +179,8 @@ function blash ()
this.prompt.focus();
} else if ( key == 9 ) {
this.prompt.focus();
if ( this.prompt.value.match ( /\s(.*)$/ ))
{
var arg = RegExp.$1;
@ -240,6 +246,8 @@ function blash ()
}
}
}
this.prompt.focus();
}
this.prompt.focus();
@ -276,6 +284,7 @@ function blash ()
this.unescapePromptSequence = function ( prompt, sequence, text, default_text )
{
var re = new RegExp ( "([^\]?)" + sequence, "g" );
prompt.replace ( /%W/g, this.path );
if ( prompt.match ( re ))
{
@ -284,5 +293,17 @@ function blash ()
return prompt;
}
this.expandPath = function ( arg )
{
if ( arg.match ( /^[^\/]/ ))
{
arg = this.path + '/' + arg;
}
arg = arg.replace ( /\/*$/, '' );
arg = arg.replace ( /\/+/, '/' );
return arg;
}
}

View file

@ -33,7 +33,7 @@
"sequence" : "%W",
"default_text" : "~",
"text" : function () {
return shell.json.basepath;
return shell.path;
},
}
],
@ -51,6 +51,10 @@
"path" : "/home/blacklight",
"type" : "directory",
},
{
"path" : "/home/blacklight/mbox",
"type" : "file",
},
{
"path" : "/etc",
"type" : "directory",

View file

@ -12,22 +12,19 @@
var out = '';
var exists = false;
arg = arg.replace ( /\/$/, '' );
if ( !arg || arg.length == 0 )
{
var re = new RegExp ( '^' + shell.path + '[^/]+$' );
} else if ( arg && arg.length > 0 ) {
var re = null;
if ( arg.match ( /^\// ))
if ( shell.path == '/' )
{
re = new RegExp ( '^' + arg + '/[^/]+$' );
re = new RegExp ( '^' + shell.path + '[^/]+$' );
} else {
re = new RegExp ( '^' + shell.path +
(( shell.path == '/' ) ? '' : '/' ) +
arg + '/[^/]+$' );
re = new RegExp ( '^' + shell.path + '/?[^/]+$' );
}
} else if ( arg && arg.length > 0 ) {
arg = shell.expandPath ( arg );
var re = new RegExp ( '^' + arg + '/[^/]+$' );
}
for ( var i=0; i < shell.json.directories.length; i++ )
@ -38,6 +35,7 @@
{
exists = true;
dir.path.match ( /\/([^\/]+)$/ );
dirs.push ({
"path" : RegExp.$1,
"type" : dir.type,
@ -106,7 +104,7 @@
{
out += '<a href="' + dirs[i].href + '" class="file" target="_new">' + dirs[i].path + '</a>*<br/>';
} else {
out += '<span class="file">' + dirs[i].path + '</span><br/>';
out += dirs[i].path + '<br/>';
}
}
}

View file

@ -8,7 +8,7 @@
<body onload="shell = new blash()">
<div id="blashWindow" onmouseup="shell.prompt.focus()">
<span id="promptText" class="promptText"></span>
<input type="text" class="promptInput" name="blashPrompt" autocomplete="off" onkeyup="shell.getKey ( event )"/>
<input type="text" class="promptInput" name="blashPrompt" autocomplete="off" onkeydown="shell.getKey ( event )" onkeyup="this.focus()"/>
<span id="blashCmdOut" class="blashCmdOut"/></span>
</div>
</body>