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 value = this.prompt.value;
var out = this.cmdOut.innerHTML; 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.prompt );
this.window.removeChild ( this.cmdOut ); 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 = document.createElement ( 'input' );
this.prompt.setAttribute ( 'name', 'blashPrompt' ); this.prompt.setAttribute ( 'name', 'blashPrompt' );
this.prompt.setAttribute ( 'type', 'text' ); this.prompt.setAttribute ( 'type', 'text' );
this.prompt.setAttribute ( 'class', 'promptInput' ); this.prompt.setAttribute ( 'class', 'promptInput' );
this.prompt.setAttribute ( 'autocomplete', 'off' ); 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 = document.createElement ( 'div' );
this.cmdOut.setAttribute ( 'id', 'blashCmdOut' ); this.cmdOut.setAttribute ( 'id', 'blashCmdOut' );
@ -175,6 +179,8 @@ function blash ()
this.prompt.focus(); this.prompt.focus();
} else if ( key == 9 ) { } else if ( key == 9 ) {
this.prompt.focus();
if ( this.prompt.value.match ( /\s(.*)$/ )) if ( this.prompt.value.match ( /\s(.*)$/ ))
{ {
var arg = RegExp.$1; var arg = RegExp.$1;
@ -240,6 +246,8 @@ function blash ()
} }
} }
} }
this.prompt.focus();
} }
this.prompt.focus(); this.prompt.focus();
@ -276,6 +284,7 @@ function blash ()
this.unescapePromptSequence = function ( prompt, sequence, text, default_text ) this.unescapePromptSequence = function ( prompt, sequence, text, default_text )
{ {
var re = new RegExp ( "([^\]?)" + sequence, "g" ); var re = new RegExp ( "([^\]?)" + sequence, "g" );
prompt.replace ( /%W/g, this.path );
if ( prompt.match ( re )) if ( prompt.match ( re ))
{ {
@ -284,5 +293,17 @@ function blash ()
return prompt; 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", "sequence" : "%W",
"default_text" : "~", "default_text" : "~",
"text" : function () { "text" : function () {
return shell.json.basepath; return shell.path;
}, },
} }
], ],
@ -51,6 +51,10 @@
"path" : "/home/blacklight", "path" : "/home/blacklight",
"type" : "directory", "type" : "directory",
}, },
{
"path" : "/home/blacklight/mbox",
"type" : "file",
},
{ {
"path" : "/etc", "path" : "/etc",
"type" : "directory", "type" : "directory",

View file

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