-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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 😉 |
Ah yes, that's something we need to work through with Canonical. |
Dang! For some reason the solution from https://docs.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory stopped working in Windows Terminal 1.13.10983.0 (or before). It's working for window splitting (panes) but not for new tabs. Using the Ubuntu image. |
Are you using "new tab" or "duplicate tab". The former doesn't carry the working directory over. |
I'm using new tab. Turns out the profile needs to properly escape single slash on Server 2022, something I didn't have to do in Windows 10/11. Fix mentioned by nuixtech fixed the issue. I have terminal installed on Windows 11 and Server 2022 (using the win10 msixbundle). This is how Ubuntu-20.04 profile looks on Windows 11. On Server 2022, this is how it looks. |
I don't understand how that makes a difference (because that path should be processed by Terminal, well before WSL sees it), but it might be worth opening as a separate specific bug report so it can be fixed in the code that auto-generates the profile, or if there's a bug elsewhere in Terminal causing this issue, that can be fixed instead. |
Are there any updates on this ? I managed to make it work for "duplicate tab" by changing |
@codtiger , thank you for your answer. It saved me :D One additional detail: with default settings, when I change "startingDirectory": "~", |
@codtiger @tristanbarcelon was irritated by this problem, thanks for the suggestions! 😄 |
Good day! I am using: Following this instruction Tutorial: Opening a tab or pane in the same directory in Windows Terminal added to PROMPT_COMMAND=${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}'printf "\e]9;9;%s\e\\" "$(wslpath -w "$PWD")"' After that, Windows Terminal began to remember directories, thanks! But other problems arose, for example, nvm broke Adding these lines to export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion I decided to write this comment because neither in the article Tutorial: Opening a tab or pane in the same directory in Windows Terminal nor in this issue did I see that adding this line PROMPT_COMMAND=${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}'printf "\e]9;9;%s\e\\" "$(wslpath -w "$PWD")"' to nvm is the first thing I tried to use, most likely there are more such problems. Did I do something wrong when I edited |
That line definitely shouldn't have broken stuff you described. It's not obvious how nvm was working, but my best-guess is that you actually newly created the If that's the case, then you could either add the |
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.
|
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: