Skip to content

Commit 43f7d43

Browse files
committed
🎁 Add support for ITerm CWD seq: OSC 1337 ; CurrentDir=<Cwd> ST
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 2c468df commit 43f7d43

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,12 @@ const enum ITermOscPt {
158158
/**
159159
* Sets a mark/point-of-interest in the buffer. `OSC 1337 ; SetMark`
160160
*/
161-
SetMark = 'SetMark'
161+
SetMark = 'SetMark',
162+
163+
/**
164+
* Reports current working directory (CWD). `OSC 1337 ; CurrentDir=<Cwd> ST`
165+
*/
166+
CurrentDir = 'CurrentDir'
162167
}
163168

164169
/**
@@ -337,7 +342,6 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
337342
switch (key) {
338343
case 'Cwd': {
339344
// TODO: Ideally we would also support the following to supplement our own:
340-
// - OSC 1337 ; CurrentDir=<Cwd> ST (iTerm)
341345
// - OSC 7 ; scheme://cwd ST (Unknown origin)
342346
// - OSC 9 ; 9 ; <cwd> ST (cmder)
343347
this._updateCwd(value);
@@ -374,7 +378,24 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
374378
case ITermOscPt.SetMark: {
375379
this._createOrGetCommandDetection(this._terminal).handleGenericCommand({ genericMarkProperties: { disableCommandStorage: true } });
376380
}
381+
default: {
382+
// Checking for known `<key>=<value>` pairs.
383+
const { key, value } = this._parseKeyValueAssignment(command);
384+
385+
if (value === undefined) {
386+
// No '=' was found, so it's not a property assignment.
387+
return true;
388+
}
389+
390+
switch (key) {
391+
case ITermOscPt.CurrentDir:
392+
// Encountered: `OSC 1337 ; CurrentDir=<Cwd> ST`
393+
this._updateCwd(value);
394+
return true;
395+
}
396+
}
377397
}
398+
378399
// Unrecognized sequence
379400
return false;
380401
}

0 commit comments

Comments
 (0)