mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
add . and .. support to lib.resolvePath, fix bugs in commands not using lib.resolvePath
This commit is contained in:
parent
53fedffe87
commit
40efd18938
2 changed files with 24 additions and 12 deletions
|
|
@ -64,8 +64,6 @@ Options:
|
|||
io.error('unknown argument: -'+args[i][j]);
|
||||
}
|
||||
}
|
||||
}else if (args[i][0] == '/') {
|
||||
dirs.push(args[i]);
|
||||
}else{
|
||||
dirs.push(clite.lib.resolvePath(args[i],false));
|
||||
}
|
||||
|
|
@ -128,8 +126,6 @@ Options:
|
|||
io.error('unknown argument: -'+args[i][j]);
|
||||
}
|
||||
}
|
||||
}else if (args[i][0] == '/') {
|
||||
files.push(args[i]);
|
||||
}else{
|
||||
files.push(clite.lib.resolvePath(args[i],false));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -992,16 +992,32 @@ clite.lib = {
|
|||
},
|
||||
// returns an absolute path: ('foo','/etc') -> '/etc/foo': ('foo','bar') -> $PWD/bar/foo
|
||||
resolvePath:function(txt,base) {
|
||||
if (txt[0] == '/')
|
||||
if (txt == '/')
|
||||
return txt;
|
||||
if (txt[0] == '~')
|
||||
return clite.shell.env.HOME+txt.substring(1);
|
||||
if (typeof base != 'string')
|
||||
base = clite.shell.env.PWD;
|
||||
if (base[0] != '/')
|
||||
base = clite.shell.env.PWD+'/'+base;
|
||||
// TODO: support . and ..
|
||||
return base+'/'+txt;
|
||||
txt = clite.shell.env.HOME+txt.substring(1);
|
||||
var path = txt;
|
||||
if (txt[0] != '/') {
|
||||
if (typeof base != 'string')
|
||||
base = clite.shell.env.PWD;
|
||||
if (base[0] != '/')
|
||||
base = clite.shell.env.PWD+'/'+base;
|
||||
path = base+'/'+txt;
|
||||
}
|
||||
var parts = path.split('/');
|
||||
path = '';
|
||||
var i;
|
||||
while ((i = parts.indexOf('.')) != -1) {
|
||||
parts.splice(i,1);
|
||||
}
|
||||
while ((i = parts.indexOf('')) != -1) {
|
||||
parts.splice(i,1);
|
||||
}
|
||||
while ((i = parts.indexOf('..')) != -1) {
|
||||
parts.splice(i-1,2);
|
||||
}
|
||||
path = '/'+parts.join('/');
|
||||
return path;
|
||||
},
|
||||
// convert a string into an argument array: 'ls /etc' -> ['ls',/etc]
|
||||
strToArgs:function(txt) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue