blash/commands/cd.json

77 lines
1.6 KiB
JSON
Raw Normal View History

2010-12-22 02:28:45 +01:00
{
"name" : "cd",
"info" : {
"syntax" : "cd <directory>",
"brief" : "Change the current directory to the specified one",
},
"action" : function ( arg )
{
var out = '';
2011-01-01 17:25:28 +01:00
if ( !arg || arg.length == 0 || arg == '~' )
2010-12-22 02:28:45 +01:00
{
2011-01-01 17:25:28 +01:00
shell.auto_prompt_focus = false;
shell.auto_prompt_refresh = false;
var users_php = window.location.href;
users_php = users_php.replace ( /\/([a-zA-Z\.]+)$/, '/modules/users/users.php' );
params = 'action=gethome';
2010-12-22 02:28:45 +01:00
2011-01-01 17:25:28 +01:00
var http = new XMLHttpRequest();
http.open ( "POST", users_php, true );
http.setRequestHeader ( "Content-type", "application/x-www-form-urlencoded" );
http.setRequestHeader ( "Content-length", params.length );
http.setRequestHeader ( "Connection", "close" );
2010-12-22 02:28:45 +01:00
2011-01-01 17:25:28 +01:00
http.onreadystatechange = function ()
2010-12-22 02:28:45 +01:00
{
2011-01-01 17:25:28 +01:00
if ( http.readyState == 4 && http.status == 200 )
{
if ( http.responseText.length > 0 )
{
shell.home = http.responseText;
shell.path = shell.home;
} else {
shell.user = shell.json.user;
}
shell.cmdOut.innerHTML = '';
shell.auto_prompt_focus = true;
shell.auto_prompt_refresh = true;
shell.refreshPrompt ( false, false );
}
}
http.send ( params );
} else {
var found = false;
arg = shell.expandPath ( arg );
2010-12-22 02:28:45 +01:00
2011-01-01 17:25:28 +01:00
for ( var i=0; i < shell.files.length && !found; i++ )
{
if ( shell.files[i].path == arg )
2010-12-22 02:28:45 +01:00
{
2011-01-01 17:25:28 +01:00
found = true;
if ( shell.files[i].type != 'directory' )
{
return "cd: not a directory: " + arg + "<br/>\n";
}
2010-12-22 02:28:45 +01:00
}
}
2011-01-01 17:25:28 +01:00
if ( !found )
{
return "cd: No such file or directory: " + arg + "<br/>\n";
}
shell.path = arg;
2010-12-22 02:28:45 +01:00
}
return out;
},
}