Skip to content

Commit

Permalink
Disable auto-cd when ${workingDirectory} is present (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Feb 17, 2022
1 parent ddfafd5 commit 749a611
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- Small improvements to Dropdown(WithInput) UI components
- 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
- 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
- Added `semver` as dependency in preparation of `FS_NOTIFY_ERRORS` flag
Expand Down
23 changes: 14 additions & 9 deletions src/pseudoTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
let { workingDirectory } = options;
workingDirectory = workingDirectory || actualConfig.root;
let cmd = joinCommands(commands, separator)!;
if (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)}"`;
if (cmd.includes('${workingDirectory}')) {
cmd = cmd.replace(/\${workingDirectory}/g, workingDirectory);
} 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 };
let cmd = joinCommands(commands, separator)!;
cmd = cmd.replace(/\${workingDirectory}/g, workingDirectory || '');
Logging.debug(`Starting shell for ${connection.actualConfig.name}: ${cmd}`);
const channel = await toPromise<ClientChannel | undefined>(cb => client.exec(cmd, { pty: pseudoTtyOptions }, cb));
if (!channel) throw new Error('Could not create remote terminal');
Expand Down

0 comments on commit 749a611

Please sign in to comment.