Replace ichwh with which and some fixes for auto-cd (canonicalization) (#1672)

* fix: absolutize path against its parent if it was a symlink.

On Linux this happens because Rust calls readlink but doesn't canonicalize the resultant path.

* feat: playground function to create symlinks

* fix: use playground dirs

* feat: test for #1631, shift tests names

* Creation of FilesystemShell with custom location may fail

* Replace ichwh with which

* Creation of FilesystemShell with custom location may fail

* Replace ichwh with which

* fix: add ichwh again since it cannot be completely replaced

* fix: replace one more use of which
This commit is contained in:
Kevin Del Castillo
2020-04-27 12:49:53 -05:00
committed by GitHub
parent 6abb9181d5
commit c704157bc8
7 changed files with 31 additions and 12 deletions

View File

@ -69,9 +69,15 @@ impl FilesystemShell {
})
}
pub fn with_location(path: String, commands: CommandRegistry) -> FilesystemShell {
pub fn with_location(
path: String,
commands: CommandRegistry,
) -> Result<FilesystemShell, std::io::Error> {
let path = canonicalize(std::env::current_dir()?, &path)?;
let path = path.display().to_string();
let last_path = path.clone();
FilesystemShell {
Ok(FilesystemShell {
path,
last_path,
completer: NuCompleter {
@ -80,7 +86,7 @@ impl FilesystemShell {
homedir: dirs::home_dir(),
},
hinter: HistoryHinter {},
}
})
}
}
@ -978,7 +984,7 @@ impl Shell for FilesystemShell {
fn set_path(&mut self, path: String) {
let pathbuf = PathBuf::from(&path);
let path = match dunce::canonicalize(pathbuf.as_path()) {
let path = match canonicalize(self.path(), pathbuf.as_path()) {
Ok(path) => {
let _ = std::env::set_current_dir(&path);
path