Skip to content

Consider using OSC 9;9 to inform Windows Terminal about CWD #8166

Closed

Description

Description of the new feature/enhancement

About a month ago I've filed #7668 , in the seek of a solution for #3158 . It raised a lot of discussion and I can totally understand why #7668 is acceptable to some people but unpalatable to others.

Recently with #8055 being accepted as a solution, I thought why not accept more sequences from ConEmu, which is a fantastic product I've personally used for a long time. So here I purpose we implement another OSC 9 custom sequence from ConEmu:

Sequence Descriptoin
ESC ] 9 ; 9 ; “cwd” ST Inform ConEmu about shell current working directory.

The source can be found in the ConEmu doc.

Proposed technical implementation details (optional)

PR: #8330

Shell configurations:

Activity

  1. added
    Issue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.
    on Nov 5, 2020
  2. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Nov 5, 2020
  3. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Nov 5, 2020
  4. skyline75489 commented on Nov 5, 2020

    @skyline75489
    CollaboratorAuthor

    CC Maksim Moisiuk (@Maximus5) for any suggestions on the remote connections.

  5. zadjii-msft commented on Nov 5, 2020

    @zadjii-msft
    Member

    I owe you a longer writeup on both this and OSC 7, and now that I'm back from leave, I don't really have any excuses 😝 I'll try to write something up later today. Thanks for your patience!

  6. skyline75489 commented on Nov 6, 2020

    @skyline75489
    CollaboratorAuthor

    Mike Griese (@zadjii-msft) It's absolutely OK. Take you time, man.

    I've been experimenting with ConEmu and OSC 9;9 sequences. From what I can tell, the result of a OSC 9;9 is an option in the "Startup directory" when creating a new console:

    image

    So yeah, I guess we could use it for #3158 without breaking the original meaning of the this sequence.

  7. added
    Area-VTVirtual Terminal sequence support
    Issue-TaskIt's a feature request, but it doesn't really need a major design.
    and removed
    Issue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.
    on Nov 8, 2020
  8. ghost removed
    Needs-Tag-FixDoesn't match tag requirements
    on Nov 8, 2020
  9. zadjii-msft commented on Nov 9, 2020

    @zadjii-msft
    Member

    (copypasta from my comment in #7668)

    This one doesn't seem that bad. Since it's a windows-first sequence, it doesn't need to know anything else about who's emitting the path. We can always assume it has been emitted as a Windows path. On the surface, this seems to work great, save for one scenario - ssh. This sequence doesn't accept any sort of hostname, it only takes the path. So if you were ssh'd into another machine, and that one emitted a OSC9;9, then there's no way of determining that sequence wasn't intended for the current machine.

    I think I'm okay with us implementing this as-is for the time being though. It's not a perfect sequence, but it's good enough, and doesn't come with the compat baggage that OSC7 does. It can certainly be supported with the caveat "This won't work in an ssh session, or in any scenario where it's emitted by a remote connection. It will always be treated as a path on the local machine".

  10. 10 remaining items

  11. Maximus5 commented on Nov 12, 2020

    @Maximus5

    As far as I can see, ConEmu will not enforce users to use CWD to open new tabs. Instead it just adds an option in the dropdown.

    That's almost true. User may configure task to use %CD% as task startup directory. I didn't make it default behavior, but think to do from time to time.

    and \w will be generating something like /home/myInWSLUser

    ConEmu can (at least should) do automatic translation of Unix path to Windows path to maintain PWD. But with /home folders it's problematic of course.
    At some point it was not working, but now as I can see, starting wsl in the folders like \\wsl$\Ubuntu-18.04\home\maximus\myInWslUser and C:\SRC works properly.
    So I tend to change \w into wslpath -m "\w" in docs for wsl.

  12. TBBle commented on Nov 12, 2020

    @TBBle

    Quick note on wslpath -m, it's possible that there's no -m, and it needs to be -w. I know cygpath -m works for MSYS/Cygwin, but I don't recall if wslpath supports it.

    It probably should be wslpath -w and cygpath -w for OSC 9;9 anyway, since the -m is "Windows path but with /", i.e. useful for appending to file://localhost/ to buld an OSC 7-valid URL.

  13. ghost added
    In-PRThis issue has a related PR
    on Nov 19, 2020
  14. ghost closed this as completedin #8330on Jan 11, 2021
  15. ghost removed
    In-PRThis issue has a related PR
    on Jan 11, 2021
  16. ghost added
    Resolution-Fix-CommittedFix is checked in, but it might be 3-4 weeks until a release.
    on Jan 11, 2021
  17. ghost added a commit that references this issue on Jan 11, 2021
    e557a86
  18. added a commit that references this issue on Jan 28, 2021
    cd7063e
  19. 3N4N commented on Oct 15, 2021

    @3N4N

    Has anyone managed to make it work for cmd? I was using pwsh with osc9;9 string, but pwsh was too slow for normal use and am thinking of using cmd for interactive use. But I cannot set it up to open the new tab/split in current directory. Help.

  20. TBBle commented on Oct 15, 2021

    @TBBle
  21. 3N4N commented on Oct 16, 2021

    @3N4N

    Yes, it works. The one I got before used OSC7 instead of 9;9.

  22. TBBle commented on Oct 16, 2021

    @TBBle

    Yeah, OSC 7 isn't implemented in Windows Terminal, due to semantic conflicts in the specifications when applied to Windows.

  23. joel-daros commented on Oct 28, 2021

    @joel-daros

    EDIT:

    Found a solution:
    https://gist.github.com/LuanVSO/5e914af7f3f038f247b6729fc43b9c7c


    I'm using Git Bash as default terminal in Window Terminal.
    What is equivalent gist to put in .bashrc so that it remembers the last folder.

    Already tried unsuccessful:

    __wt_osc9_9 () {
        _win_path=$(pwd)
        printf "\033]9;9;%s\033\\" "$_win_path"
    }
    
    [ -n "$BASH_VERSION" ] && [ -n "$WT_SESSION" ] && PROMPT_COMMAND="__wt_osc9_9"
    
    true
    

    when terminal reopens it shows that error:

    [error -2147024629 (-0x7ff8fef5) when launching `%USERPROFILE%/AppData/Local/Programs/Git/bin/bash.exe -l -i']
    Could not access starting directory "/c/WINDOWS/system32"
    
  24. bsclifton commented on Feb 26, 2025

    @bsclifton

    I know it's been a few years - but thanks Joel (@joel-daros)! I added that snippet to my .bashrc and it works great 😄

    EDIT:

    Found a solution:
    https://gist.github.com/LuanVSO/5e914af7f3f038f247b6729fc43b9c7c

  25. trajano commented on Sep 18, 2025

    @trajano

    #8166 (comment)

    Yeah, OSC 7 isn't implemented in Windows Terminal, due to semantic conflicts in the specifications when applied to Windows.

    Is there some sort of document/discussion that says what these conflicts are? I am curious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-VTVirtual Terminal sequence supportIssue-TaskIt's a feature request, but it doesn't really need a major design.Product-TerminalThe new Windows Terminal.Resolution-Fix-CommittedFix is checked in, but it might be 3-4 weeks until a release.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions