shell pathfill

This commit is contained in:
Lisa Milne 2023-12-18 20:46:56 +10:00
parent 9ad4b23a6c
commit 733ee75dd2
3 changed files with 30 additions and 7 deletions

View file

@ -147,6 +147,8 @@ Options:
if (st.type != stdio.types.FT_DIR) {
writeNodeData(st,fd);
stdio.close(fd);
if (!one && !long)
stdio.write(io.stdout,'\n');
return;
}
var e;

View file

@ -1312,7 +1312,6 @@ cat -l /usr/share/introduction
clite.user.hasAltLogin = function() {
let r = false;
data.users.forEach(function(u) {
console.log(u.name+':'+u.pass);
if (u.name != 'root' && u.pass != 'x')
r = true;
});
@ -2613,7 +2612,6 @@ clite.vfs = {
return true;
}
clite.vfs.restoreFile = function(path) {
console.log('restore: '+path);
var b = clite.state.bios.io.read(2);
if (!b)
return false;

View file

@ -932,12 +932,12 @@ Options:
});
if (add == '') {
// test for commands
var pparts = env.PATH.split(':');
let pparts = env.PATH.split(':');
pparts.forEach(function(pp) {
if (add != '')
return;
var fd = stdio.open('/bin',stdio.flags.O_SEARCH|stdio.flags.O_DIRECTORY);
var f;
let fd = stdio.open('/bin',stdio.flags.O_SEARCH|stdio.flags.O_DIRECTORY);
let f = null;
while (add == '' && (f = stdio.read(fd)) != null) {
if (f.substring(0,a.length) == a) {
add = f.substring(a.length)+' ';
@ -946,8 +946,29 @@ Options:
stdio.close(fd);
});
}
}else{
}else if (a != '') {
// TODO: path fill
let p = clite.resolvePath(a);
if (p[0] == '/') {
let d = stdlib.dirname(p);
let b = stdlib.basename(p);
if (d == '')
d = '/';
let fd = stdio.open(d,stdio.flags.O_SEARCH|stdio.flags.O_DIRECTORY);
if (fd) {
let f = null;
while (add == '' && (f = stdio.read(fd)) != null) {
if (f.substring(0,b.length) == b) {
add = f.substring(b.length);
let fp = d+'/'+f;
let st = stdio.stat(fp);
if (st && st.type != stdio.types.FT_DIR)
add += ' ';
}
}
stdio.close(fd);
}
}
}
if (add == '')
return null;
@ -991,6 +1012,8 @@ Options:
if (ct != null) {
c = ct;
cc = c.length;
}else{
stdio.write(io.stdout,'\b \b');
}
break;
case '\n': // enter
@ -1034,7 +1057,7 @@ Options:
}
break;
default:
if (typeof str === 'string') {
if (typeof str === 'string' && str.length == 1) {
c += str;
cc++;
history.setCurrent(c);