Add ${workingDirectory} variable to terminal commands (#323)

pull/373/head
Kelvin Schoofs 3 years ago
parent 8c8b95016a
commit ddfafd5b4b

@ -4,7 +4,10 @@
## Unreleased
### New features
- Add `FS_NOTIFY_ERRORS` flag to display notifications for FS errors (#282)
- Added `FS_NOTIFY_ERRORS` flag to display notifications for FS errors (#282)
- Added a `${workingDirectory}` variable that gets replaced during terminal creation (#323)
- This applies to both the `Terminal Command` setting and `ssh-shell` task type
- See the issue (#323) for why this got added and how you can use it
### Changes
- Small improvements to Dropdown(WithInput) UI components

@ -205,7 +205,8 @@ export async function createTerminal(options: TerminalOptions): Promise<SSHPseud
commands.unshift(`cd ${workingDirectory}`);
}
const pseudoTtyOptions: PseudoTtyOptions = { ...PSEUDO_TTY_OPTIONS, cols: dims?.columns, rows: dims?.rows };
const cmd = joinCommands(commands, separator)!;
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');

@ -80,7 +80,7 @@ export function validatePort(port: string | number): number {
const CLEAN_BASH_VALUE_REGEX = /^[\w-/\\]+$/;
/** Based on way 1 in https://stackoverflow.com/a/20053121 */
function escapeBashValue(value: string) {
export function escapeBashValue(value: string) {
if (CLEAN_BASH_VALUE_REGEX.test(value)) return value;
return `'${value.replace(/'/g, `'\\''`)}'`;
}

Loading…
Cancel
Save