mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
add support for opening a file without loading, fix a resolvePath bug in touch, add file command
This commit is contained in:
parent
43ada86383
commit
3906795007
2 changed files with 92 additions and 6 deletions
|
|
@ -218,11 +218,7 @@ Options:
|
|||
}
|
||||
}
|
||||
}else if (file == null) {
|
||||
if (args[i][0] == '/') {
|
||||
file = args[i];
|
||||
}else{
|
||||
file = stdlib.resolvePath(args[i],false);
|
||||
}
|
||||
file = stdlib.resolvePath(args[i],false);
|
||||
}else{
|
||||
io.error('unknown argument: '+args[i]);
|
||||
}
|
||||
|
|
@ -242,14 +238,102 @@ Options:
|
|||
});
|
||||
|
||||
clite.commands.load('less',function(args,env,io) {
|
||||
io.write('less is under development');
|
||||
return 0;
|
||||
});
|
||||
|
||||
clite.commands.load('view',function(args,env,io) {
|
||||
io.write('view is under development');
|
||||
return 0;
|
||||
});
|
||||
|
||||
clite.commands.load('edit',function(args,env,io) {
|
||||
io.write('edit is under development');
|
||||
return 0;
|
||||
});
|
||||
|
||||
clite.commands.load('file',function(args,env,io) {
|
||||
var short = '';
|
||||
var file = null;
|
||||
var stdlib = io.include('stdlib');
|
||||
var stdio = io.include('stdio');
|
||||
function help() {
|
||||
io.write(`
|
||||
file - determine type of FILE
|
||||
Usage: touch [OPTION] [FILE]
|
||||
|
||||
Options:
|
||||
-? Print this help information
|
||||
`);
|
||||
}
|
||||
|
||||
for (var i=1; i<args.length; i++) {
|
||||
if (args[i][0] == '-') {
|
||||
for (var j=1; j<args[i].length; j++) {
|
||||
switch (args[i][j]) {
|
||||
case '?':
|
||||
help();
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
io.error('unknown argument: -'+args[i][j]);
|
||||
}
|
||||
}
|
||||
}else if (file == null) {
|
||||
short = args[i];
|
||||
file = stdlib.resolvePath(args[i],false);
|
||||
}else{
|
||||
io.error('unknown argument: '+args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (file == null) {
|
||||
io.error('no file specified');
|
||||
return 1;
|
||||
}
|
||||
|
||||
var fd = stdio.open(file,false);
|
||||
if (!fd) {
|
||||
io.error('cannot open file: '+file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var t = stdlib.getFileType(fd);
|
||||
stdio.close(fd);
|
||||
|
||||
var txt = short+': ';
|
||||
switch (t) {
|
||||
case 1:
|
||||
txt += 'Plain Text';
|
||||
break;
|
||||
case 2:
|
||||
txt += 'CLIte Executable';
|
||||
break;
|
||||
case 3:
|
||||
txt += 'Directory';
|
||||
break;
|
||||
case 4:
|
||||
txt += 'Link';
|
||||
break;
|
||||
case 5:
|
||||
txt += 'Device File';
|
||||
break;
|
||||
case 6:
|
||||
txt += 'Unloaded Remote Data';
|
||||
break;
|
||||
case 7:
|
||||
txt += 'Shell Script';
|
||||
break;
|
||||
case 8:
|
||||
txt += 'Image';
|
||||
break;
|
||||
default:
|
||||
txt += 'Unknown Data';
|
||||
break;
|
||||
}
|
||||
|
||||
io.write(txt);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -326,7 +326,9 @@ clite.io = {
|
|||
callback:cb
|
||||
}
|
||||
});
|
||||
if (p) {
|
||||
if (cb == false) {
|
||||
fd.remote.callback = null;
|
||||
}else if (p) {
|
||||
clite.core.load.file(n.data.remote,function(d) {
|
||||
n.data.content = d;
|
||||
fd.remote.ispending = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue