diff --git a/src/manager.ts b/src/manager.ts index b1ce63d..9fa76e7 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -240,12 +240,14 @@ export class Manager implements vscode.TreeDataProvider fs.config.name === name); - workingDirectory = fs ? fs.relative(workingDirectory) : undefined; + workingDirectory = fs ? fs.relative(workingDirectory) : (con.actualConfig.root || '/'); + // If we don't have an FS (e.g. SSH View > Open Terminal without an active FS), we + // just use the declared `root` field, which _hopefully_ works out nicely with `cd` } // Create pseudo terminal con.pendingUserCount++; @@ -372,11 +374,11 @@ export class Manager implements vscode.TreeDataProvider( `Couldn't start a terminal for ${name}: ${e.message || e}`, diff --git a/src/pseudoTerminal.ts b/src/pseudoTerminal.ts index f3bf42e..f589e90 100644 --- a/src/pseudoTerminal.ts +++ b/src/pseudoTerminal.ts @@ -29,7 +29,16 @@ export async function createTerminal(client: Client, config: FileSystemConfig, w // Hopefully the exit event fires first channel.on('close', () => onDidClose.fire(0)); // There isn't a proper way of setting the working directory, but this should work in most cases - if (workingDirectory) channel.write(`cd "${workingDirectory}"\n`); + if (workingDirectory) { + if (workingDirectory.startsWith('~')) { + // So `cd "~/a/b/..." apparently doesn't work, but `~/"a/b/..."` does + // `"~"` would also fail but `~/""` works fine it seems + workingDirectory = `~/"${workingDirectory.substr(2)}"`; + } else { + workingDirectory = `"${workingDirectory}"`; + } + channel.write(`cd ${workingDirectory}\n`); + } const pseudo: SSHPseudoTerminal = { config, client, channel, onDidWrite: onDidWrite.event,