blash/commands/cd.js

74 lines
1.5 KiB
JavaScript
Raw Permalink 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;
2022-10-17 01:12:44 +02:00
var users_php = './modules/users/users.php';
2011-01-01 17:25:28 +01:00
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 ( "Connection", "close" );
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;
2011-01-10 22:31:56 +01:00
if ( shell.files[i].link_to && shell.files[i].link_to.length > 0 ) {
return this.action ( shell.files[i].link_to );
} else if ( shell.files[i].type != 'directory' ) {
2011-01-01 17:25:28 +01:00
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;
},
}