You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider using OSC 9;9 to inform Windows Terminal about CWD #8166
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.
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!
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:
So yeah, I guess we could use it for #3158 without breaking the original meaning of the this sequence.
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".
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.
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.
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.
[error -2147024629 (-0x7ff8fef5) when launching `%USERPROFILE%/AppData/Local/Programs/Git/bin/bash.exe -l -i']
Could not access starting directory "/c/WINDOWS/system32"
Activity
skyline75489 commentedon Nov 5, 2020
CC Maksim Moisiuk (@Maximus5) for any suggestions on the remote connections.
zadjii-msft commentedon Nov 5, 2020
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!
skyline75489 commentedon Nov 6, 2020
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:
So yeah, I guess we could use it for #3158 without breaking the original meaning of the this sequence.
zadjii-msft commentedon Nov 9, 2020
(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 weressh'd into another machine, and that one emitted aOSC9;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
OSC7does. 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 remaining items
Maximus5 commentedon Nov 12, 2020
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.ConEmu can (at least should) do automatic translation of Unix path to Windows path to maintain PWD. But with
/homefolders 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\myInWslUserandC:\SRCworks properly.So I tend to change
\wintowslpath -m "\w"in docs for wsl.TBBle commentedon Nov 12, 2020
Quick note on
wslpath -m, it's possible that there's no-m, and it needs to be-w. I knowcygpath -mworks for MSYS/Cygwin, but I don't recall ifwslpathsupports it.It probably should be
wslpath -wandcygpath -wfor OSC 9;9 anyway, since the-mis "Windows path but with/", i.e. useful for appending tofile://localhost/to buld an OSC 7-valid URL.Implement ConEmu's OSC 9;9 to set the CWD (#8330)
Implement ConEmu's OSC 9;9 to set the CWD (microsoft#8330)
3N4N commentedon Oct 15, 2021
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.
TBBle commentedon Oct 15, 2021
https://gist.github.com/LuanVSO/09ba0239fe7c1a959a9b07c7156c5e13 from #3158 (comment) might work. (I haven't tried it)
3N4N commentedon Oct 16, 2021
Yes, it works. The one I got before used OSC7 instead of
9;9.TBBle commentedon Oct 16, 2021
Yeah,
OSC 7isn't implemented in Windows Terminal, due to semantic conflicts in the specifications when applied to Windows.joel-daros commentedon Oct 28, 2021
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:
when terminal reopens it shows that error:
bsclifton commentedon Feb 26, 2025
I know it's been a few years - but thanks Joel (@joel-daros)! I added that snippet to my .bashrc and it works great 😄
trajano commentedon Sep 18, 2025
#8166 (comment)
Is there some sort of document/discussion that says what these conflicts are? I am curious.