pass OSC7 and/or OSC9;9 info as profile "commandline" variable #22330

Open
opened 2026-01-31 08:09:59 +00:00 by claunia · 0 comments
Owner

Originally created by @reardonia on GitHub (Oct 1, 2024).

Description of the new feature/enhancement

Currently, WT supports the OSC9;9 escape sequence to set current-working-directory and uses that for local duplication of WSL, cmd, and Powershell sessions. It offers nothing for remote sessions, such as ssh.

Sidestepping the very long conversation at #12961 and elsewhere which attempts a perfect and standarized solution, it would be very helpful to propagate into an environment variable the info grabbed by WT from an OSC7 or OSC9;9 escape sequence. This ignores what WT should do internally during a "duplicate" and instead just allows for script or commandline mangling by skilled users.

A profile could then look like:
{ "commandline": "ssh.exe -t myname@myserver \" cd %WT_OSC9_9_PATH% ; bash --login \" ", ... }

See also the conversation from here:
https://github.com/microsoft/terminal/issues/12961#issuecomment-2380840336

It's not possible today to clone remote ssh sessions and maintain the current-working-directory. Remote sessions to a single server are by far the most common case; tunneling and nested ssh sessions are relatively rare. There are edge cases pointed out exhaustively in #12961 and #3158, but this solution takes care of the common case and keeps WT from having to implement further hacks as was done for WSL.

Proposed technical implementation details (optional)

AFAICT, there is no support within WT to use environment variables or other state variables within a profile commandline. It may be valuable to broaden this feature to allow for other state variables to be passed into commandline.

One possible implementation is to use %WT_OSC7_PATH% and %WT_OSC9_9_PATH%

Either (1) add %WT_OSC7_PATH% and %WT_OSC9_9_PATH% to the environment when launching a duplicate profile or (2) make %WT_OSC7_PATH% and %WT_OSC9_9_PATH% and other state variables available when parsing profile commandline

Originally created by @reardonia on GitHub (Oct 1, 2024). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement Currently, WT supports the OSC9;9 escape sequence to set current-working-directory and uses that for *local* duplication of WSL, cmd, and Powershell sessions. It offers nothing for remote sessions, such as ssh. Sidestepping the very long conversation at #12961 and elsewhere which attempts a perfect and standarized solution, it would be very helpful to propagate into an environment variable the info grabbed by WT from an OSC7 or OSC9;9 escape sequence. This ignores what WT should do internally during a "duplicate" and instead just allows for script or commandline mangling by skilled users. A profile could then look like: `{ "commandline": "ssh.exe -t myname@myserver \" cd %WT_OSC9_9_PATH% ; bash --login \" ", ... }` See also the conversation from here: https://github.com/microsoft/terminal/issues/12961#issuecomment-2380840336 <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> It's not possible today to clone *remote* ssh sessions and maintain the current-working-directory. Remote sessions to a single server are by far the most common case; tunneling and nested ssh sessions are relatively rare. There are edge cases pointed out exhaustively in #12961 and #3158, but this solution takes care of the common case and keeps WT from having to implement further hacks as was done for WSL. # Proposed technical implementation details (optional) ~~AFAICT, there is no support within WT to use environment variables or other state variables within a profile `commandline`. It may be valuable to broaden this feature to allow for other state variables to be passed into `commandline`.~~ One possible implementation is to use `%WT_OSC7_PATH%` and `%WT_OSC9_9_PATH%` <!-- A clear and concise description of what you want to happen. --> Either (1) add `%WT_OSC7_PATH%` and `%WT_OSC9_9_PATH%` to the environment when launching a duplicate profile or (2) make `%WT_OSC7_PATH%` and `%WT_OSC9_9_PATH%` and other state variables available when parsing profile `commandline`
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-FixProduct-Terminal labels 2026-01-31 08:10:00 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22330