Skip to content

Commit

Permalink
Add ${workingDirectory} variable to terminal commands (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Feb 17, 2022
1 parent 8c8b950 commit ddfafd5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/pseudoTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, `'\\''`)}'`;
}
Expand Down

0 comments on commit ddfafd5

Please sign in to comment.