mirror of
https://github.com/sigmasternchen/webcli
synced 2025-03-15 06:08:54 +00:00
ls can handle shortened paths relative to working directory
This commit is contained in:
parent
9bd7da0829
commit
a98c382a07
1 changed files with 19 additions and 7 deletions
|
@ -2,10 +2,22 @@ var Ls = function() {
|
|||
}
|
||||
Ls.prototype = new Program();
|
||||
Ls.prototype.main = function(args) {
|
||||
|
||||
if (args.length == 1)
|
||||
args[1] = shell.directory;
|
||||
if (args[1].substring(0, 1) != "/")
|
||||
args[1] = shell.directory + "/" + args[1];
|
||||
|
||||
var result = new Request("backend/ls.php");
|
||||
result.setData([["path", args.length > 1 ? args[1] : shell.directory]]);
|
||||
result.setData([["path", args[1]]]);
|
||||
result = result.send(true, ret);
|
||||
result = JSON.parse(result);
|
||||
|
||||
if (result.error) {
|
||||
this.output("\033[31m" + args[0] + ": " + result.error + "\033[0m\n");
|
||||
this.exit(1);
|
||||
}
|
||||
|
||||
var spaces = [10, -0, -0, -0, -0, 12, -0];
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
if (result[i].hardlinks.length > spaces[1])
|
||||
|
@ -16,21 +28,21 @@ Ls.prototype.main = function(args) {
|
|||
spaces[3] = result[i].group.length;
|
||||
if (result[i].size.length > spaces[4])
|
||||
spaces[4] = result[i].size.length;
|
||||
if (result[i].name.length > spaces[4])
|
||||
spaces[4] = result[i].name.length;
|
||||
if (result[i].name.length > spaces[6])
|
||||
spaces[6] = result[i].name.length;
|
||||
}
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
this.output(result[i].permission + " ");
|
||||
for (var j = 0; j < spaces[1] - result[i].hardlinks.length; j++)
|
||||
this.output(" ");
|
||||
this.output(result[i].hardlinks + " ");
|
||||
this.output(result[i].owner);
|
||||
for (var j = 0; j < spaces[3] - result[i].owner.length; j++)
|
||||
this.output(result[i].owner + " ");
|
||||
for (var j = 0; j < spaces[2] - result[i].owner.length; j++)
|
||||
this.output(" ");
|
||||
this.output(result[i].group);
|
||||
this.output(result[i].group + " ");
|
||||
for (var j = 0; j < spaces[3] - result[i].group.length; j++)
|
||||
this.output(" ");
|
||||
for (var j = 0; j < spaces[2] - result[i].size.length; j++)
|
||||
for (var j = 0; j < spaces[4] - result[i].size.length; j++)
|
||||
this.output(" ");
|
||||
this.output(result[i].size + " ");
|
||||
this.output(this.formatTime(parseInt(result[i].changed)) + " ");
|
||||
|
|
Loading…
Reference in a new issue