Fix default working directory for terminals + setting working directory when root starts with "~"

pull/208/head
Kelvin Schoofs 4 years ago
parent a7fafedd7e
commit 484a6ab242

@ -240,12 +240,14 @@ export class Manager implements vscode.TreeDataProvider<string | FileSystemConfi
// Create connection (early so we have .actualConfig.root)
const con = await this.createConnection(name, config);
// Calculate working directory if applicable
let workingDirectory: string | undefined = uri ? uri.path : con.actualConfig.root || '/';
let workingDirectory: string | undefined = uri && uri.path;
if (workingDirectory) {
// Normally there should be a fs, as (currently) workingDirectory is only provided
// when the user uses "Open remote SSH terminal" on a directory in the explorer view
const fs = this.fileSystems.find(fs => 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++;

@ -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,

Loading…
Cancel
Save