Disable auto-cd when ${workingDirectory} is present (#323)

pull/373/head
Kelvin Schoofs 3 years ago
parent ddfafd5b4b
commit 749a61191e

@ -13,6 +13,8 @@
- Small improvements to Dropdown(WithInput) UI components - Small improvements to Dropdown(WithInput) UI components
- Delay and wait for loadConfigs() after logging version info - Delay and wait for loadConfigs() after logging version info
- This solves a small issue/annoyance where logs regarding loading logs appear before the version logging - This solves a small issue/annoyance where logs regarding loading logs appear before the version logging
- When `${workingDirectory}` is present in a terminal command, the extension doesn't auto-`cd` anymore
- Normally the extension runs `cd <workingDirectory>; <terminalCommand>` or similar
### Development changes ### Development changes
- Added `semver` as dependency in preparation of `FS_NOTIFY_ERRORS` flag - Added `semver` as dependency in preparation of `FS_NOTIFY_ERRORS` flag

@ -193,20 +193,25 @@ export async function createTerminal(options: TerminalOptions): Promise<SSHPseud
// There isn't a proper way of setting the working directory, but this should work in most cases // There isn't a proper way of setting the working directory, but this should work in most cases
let { workingDirectory } = options; let { workingDirectory } = options;
workingDirectory = workingDirectory || actualConfig.root; workingDirectory = workingDirectory || actualConfig.root;
let cmd = joinCommands(commands, separator)!;
if (workingDirectory) { if (workingDirectory) {
// TODO: Maybe replace with `connection.home`? if (cmd.includes('${workingDirectory}')) {
if (workingDirectory.startsWith('~')) { cmd = cmd.replace(/\${workingDirectory}/g, workingDirectory);
// 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 { } else {
workingDirectory = `"${workingDirectory}"`; // TODO: Maybe replace with `connection.home`?
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}"`;
}
cmd = joinCommands([`cd ${workingDirectory}`, ...commands], separator)!;
} }
commands.unshift(`cd ${workingDirectory}`); } else {
cmd = cmd.replace(/\${workingDirectory}/g, '');
} }
const pseudoTtyOptions: PseudoTtyOptions = { ...PSEUDO_TTY_OPTIONS, cols: dims?.columns, rows: dims?.rows }; const pseudoTtyOptions: PseudoTtyOptions = { ...PSEUDO_TTY_OPTIONS, cols: dims?.columns, rows: dims?.rows };
let cmd = joinCommands(commands, separator)!;
cmd = cmd.replace(/\${workingDirectory}/g, workingDirectory || '');
Logging.debug(`Starting shell for ${connection.actualConfig.name}: ${cmd}`); Logging.debug(`Starting shell for ${connection.actualConfig.name}: ${cmd}`);
const channel = await toPromise<ClientChannel | undefined>(cb => client.exec(cmd, { pty: pseudoTtyOptions }, cb)); const channel = await toPromise<ClientChannel | undefined>(cb => client.exec(cmd, { pty: pseudoTtyOptions }, cb));
if (!channel) throw new Error('Could not create remote terminal'); if (!channel) throw new Error('Could not create remote terminal');

Loading…
Cancel
Save