Fix path-related parts of value shell

This commit is contained in:
Jonathan Turner 2019-08-27 17:15:05 +12:00
parent 1d64d90419
commit 570a0ac275

View file

@ -84,19 +84,20 @@ impl Shell for ValueShell {
let path = match args.nth(0) {
None => "/".to_string(),
Some(v) => {
let target = v.as_string()?;
let target = v.as_path()?;
let mut cwd = PathBuf::from(&self.path);
match target {
x if x == ".." => {
cwd.pop();
if target == PathBuf::from("..") {
cwd.pop();
} else {
match target.to_str() {
Some(target) => match target.chars().nth(0) {
Some(x) if x == '/' => cwd = PathBuf::from(target),
_ => cwd.push(target),
},
None => cwd.push(target),
}
_ => match target.chars().nth(0) {
Some(x) if x == '/' => cwd = PathBuf::from(target),
_ => {
cwd.push(target);
}
},
}
cwd.to_string_lossy().to_string()
}