-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open new terminal tab in same directory as existing tab (OSC 7?) #3158
Comments
There's a "standard" escape sequence (OSC 7 ; URI ST) to set the terminal emulator's belief about the current directory. It originates from macOS Terminal.app, and was later adopted by some other ones, including GNOME Terminal and as far as I know Konsole too. Another possible approach is to do some OS-specific hacks to examine the inner state of the child process (or even further down to descendents). Yet another possibility is to mix the two, e.g. go to the directory set via OSC 7 if it was ever emitted, otherwise dig into the process. The advantage of the OSC 7 approach is that it's clever regarding when to and when not to follow a child process. E.g. you start another nested subshell, it'll be the subdirectory of that subshell that's taken into account because that one also emits this sequence. However, launch an app that internally changes directory (e.g. make) and it – luckily – won't be make's internal subdir that's used. The disadvantage of OSC 7 is that it requires cooperation from the shell, or other apps that matter. |
I've been rejecting this feature request for as long as this project has been open-source, and I never learned about OSC 7. This is very exciting. I'm not happy to crawl through the process tree to dig up the leafmost process's CWD, but I am extremely happy to support OSC 7. |
FYI I asked about OSC 7 handling for Alacritty, which eventually led to this issue being created in the "Terminal WG" on gitlab: https://gitlab.freedesktop.org/terminal-wg/specifications/issues/20 There's not been much movement on that ticket, but you may be interested to follow it. Especially if you guys have any opinions regarding what a "formal" specification for OSC 7 might look like. |
So for the record, the thread at alacritty/alacritty#2937 has a pretty great discussion. Honestly, I'm pretty okay using the de-facto standard that's already in place, the Wait no I had a terrible thought. Say
Do we need to add some property on our side that indicates "this is a WSL distro, not a Windows exe"? What happens to users who don't set that, does the duplicate tab functionality just not work (effectively silently)? Then the next part gets harder. What happens when this command is output over SSH? The terminal can't know that the path isn't on this machine anymore, right? How does Terminal.app handle this? Maybe this does need more specification 😨 |
(Off: How long is it going to be until I mix up the two of you, D Howett and D Hewitt? :)) |
This is a crucial missing feature. |
This should be a config option for the different commands. For example, I'd like this for |
the escape sequence is documented in mac os terminal.app preferences as shown by this comment alacritty/alacritty#2937(comment)
|
For the record, there's heated debate over in https://gitlab.freedesktop.org/terminal-wg/specifications/merge_requests/7 about the specification of exactly this feature. I doubt that we'll support any subset of this feature until there's an actually accepted proposal there - we'd rather not introduce another disparate implementation until there's an actual standard. |
I'd recommend you to do the opposite :) Quite a few terminals have successfully implemented OSC 7, copying from each other, resulting in happy users. And there is somebody out there currently who thinks it isn't good enough, he thinks a formal specification is needed; comes up with a draft that is full of problems, and what I cannot understand at all, is only willing to document one of two siblings. (Note: I stopped following that thread a couple of days ago.) Terminal-WG is not a formal authority, its documents aren't "official", aren't "standards" in any de jure way. It doesn't even have proper procedures, people with responsibilities, voting rights, whatever; no one knows what it takes to get a document "accepted" there, whatever this status means at all. It's just a collection of random unorganized folks trying to come up with something useful. Don't let those unofficial pending debates stop you from implementing a long-proven feature. |
i commented it on the issue referenced in that pr too 😉 |
Thank you! Important clarification — I did not do anything unusual, on the contrary, yesterday I performed a clean installation of Indeed, adding Thanks again! Cheers! |
Okay, so it might make sense to add a note to the docs along the lines of "If The current instructions do not say to create the file, but in this situation, it's a reasonable guess that happens to do the wrong thing. I note the MINGW instructions use |
The creator of powerlevel10k has created a Zsh plugin for this. Linking it here for visibility: |
I don't know the zsh ecosystem, but is that plugin widely-suitable-enough to be added as a preferred option to the Windows Terminal docs? It's clearly too-long to inline into the docs (and is doing a lot more than the one-liner does, such as caching, some TMUX-specific magic and for some reason using If zsh plugin managers are commonly used, then that's even better, IMHO. The main concern I envisage is making the docs dependent on an external site. |
In regard to comments made by alkorlos and TBBle.
First few lines of
Solutions:
or
|
why is this not implemented even 5 years later? i don't think this is unreasonable for any web developer working on a project that requires to spin up >2 scripts in the same directory. |
Well, I mean, it has and it hasn't. You've been able to use shell integration to open a new tab/pane in the same CWD for a couple years now, using Alas, automagic CWD detection (like linux) will almost certainly never work, as some shells (cough powershell) don't actually set their CWD. Then there's of course the potential for automatically modifying people's prompts, such that shell integration is automatically enabled for them. This is definitely something that I want to investigate going forward, maybe sometime next year. But I doubt that'll work for everyone or every shell. |
I know this is an old topic but I just wanted to say for anyone trying to get split panes to same directory using GitBash in 2024, adding this line to .bashrc finally worked for me. The previously listed command by JahzVH was not working correctly for me and would give an error ping every time a prompt was input into terminal.
|
Hi @zadjii-msft , you mentioned shell integration which works fine in Powershell, but when I configure my wsl / zsh using the method described in it, the root directory still opens when I split the pane. I'm trying to understand if I'm missing something? |
@Daydreamer-riri I'd suggest checking what settings are used to launch WSL. I don't know if it's still the default, but IIRC it used to default to including a path on the command line (so it wouldn't start in Also worth checking if you haven't already that nothing else in your zsh startup scripts are changing the current directory, e.g., see point 1 of #3158 (comment). For example, this Ubuntu WSL config block works for me with the bash setup from the shell integration docs:
If changing the |
Hi @TBBle, the settings in my Terminal are: I found something interesting: when I use the former (which is, the source is |
Try adding a manual commandLine to the non-working profile, something like Anyway, I did some more digging: I have a different Ubuntu build installed ( If you confirm that adding a Edit: Gah. Turns out we already have a bug in this repo for this issue, #12961, which provides a simpler In short, I think this will work to fix your issue: In the second profile, add the following two lines to the start: "commandLine": "ubuntu.exe run",
"startingDirectory": "~", |
Thank you very much for your survey. It's incredible to have accomplished so much work in such a short time. However, after I added these two lines to the configuration, everything behaved the same as before, with no improvement. |
I have not set up "commandline". The configuration was automatically generated after installing WSL: {
"colorScheme": "Chester",
"guid": "{acbafd15-cbbb-5bb3-8a61-bed446ff4b83}",
"hidden": false,
"name": "Ubuntu 24.04 LTS",
"opacity": 95,
"source": "CanonicalGroupLimited.Ubuntu24.04LTS_79rhkp1fndgsc"
} When I set the |
Yes, that works because by changing the source, you're changing the profile you're inheriting from Ubuntu's one, to the built-in profile that includes the two lines I shared. If you do that, you may as well just unhide the actual profile generated by Windows Terminal, and hide the Ubuntu-generated one, to avoid any risk of confusion in-future. (If you go this way, you can add Ubuntu to the list of profile generators to ignore, and then remove that generated profile entirely, for a cleaner config file.) Can you share the version of that profile with the two lines I provided added, that wasn't working, so if we can see if there's anything else needed? I expect this should work, is that what you had? {
"commandLine": "ubuntu2204.exe run",
"startingDirectory": "~",
"colorScheme": "Chester",
"guid": "{acbafd15-cbbb-5bb3-8a61-bed446ff4b83}",
"hidden": false,
"name": "Ubuntu 24.04 LTS",
"opacity": 95,
"source": "CanonicalGroupLimited.Ubuntu24.04LTS_79rhkp1fndgsc"
} |
Sorry, the configuration you provided works, the reason I said it didn't work before was because I filled in the name of the executable wrong (my ubuntu version is 2404 but I wrote 2204). The only problem with it now is that my wsl default directory becomes my Windows user directory instead of the user directory in wsl. When I set commandline to |
Ah yeah, sorry about getting the number wrong. I originally typed "2004" out of habit, and fixed it looking at the example in the other ticket, not your settings. >_< Anyway, I'd go with the Otherwise, you can also put your real desired startup directory in the Sadly, it turns out Windows Terminal makes the |
Thank you! Thanks for your guidance. I think it should be stated in the documentation that “Opening a tab or pane in the same directory” requires some extra work when using the default generated Hopefully this will help more people. |
The problem is the There's some work that could be done in Windows Terminal, but it wouldn't be Ubuntu-specific and would require coordination with any such WSL distributions in their profile contributions too. |
Hi @Daydreamer-riri mentioned
|
Description of the new feature/enhancement
Have the option (or default) of a new terminal tab opening in the current directory of the window of which you hit the hotkey to open a new tab. This is the standard way most linux terminals work and is most handy. I often work in a directory where I need to launch multiple seperate processes, its a pain to CD back into the directory each time.
Proposed technical implementation details (optional)
Hit the new tab hotkey, the new terminal should then be in the same folder as the previouse.
maintainer edit: Before commenting, make sure to check out
Tutorial: Opening a tab or pane in the same directory in Windows Terminal
This is largely something configurable today, this issue is just tracking another way of configuring this
The text was updated successfully, but these errors were encountered: