Skip to content
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

Implement ConEmu's OSC 9;9 to set the CWD #8330

Merged
4 commits merged into from
Jan 11, 2021

Conversation

skyline75489
Copy link
Collaborator

@skyline75489 skyline75489 commented Nov 19, 2020

Summary of the Pull Request

This PR implement the OSC 9;9

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

References

#8214

PR Checklist

  • Closes Consider using OSC 9;9 to inform Windows Terminal about CWD #8166
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Documentation updated. If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated.
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@ghost ghost added Area-VT Virtual Terminal sequence support Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Nov 19, 2020
@skyline75489
Copy link
Collaborator Author

So this is basically a reborn version of #7668 . Thanks to prior work of @PankajBhojwani, this PR is even smaller than #7688 .

Based on previous thread like #3158 and #8214, I'd like to implement OSC 9;9 as a "Windows-first" sequence that will assume users will set Windows path . This can be seen as a starter towards a more comprehensive implementation of OSC 7, which will handle all kinds of paths based on the profile used.

As for this PR, it gives users the ability to make use the of the CWD when duplicating the current active tab. I don't really know how to handle splitting panes so I left it unchanged.

I'd like to hear you guys opinions.

@@ -1015,6 +1015,13 @@ namespace winrt::TerminalApp::implementation
if (profileGuid.has_value())
{
const auto settings{ winrt::make<TerminalSettings>(_settings, profileGuid.value(), *_bindings) };
const auto workingDirectory = terminalTab->GetActiveTerminalControl().WorkingDirectory();
const auto validWorkingDirectory = !workingDirectory.empty();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I relaxed the validation per the comments by @zadjii-msft in #8166 (comment)

I'm not sure how we handle wt -d c:\some\invalid\path nowadays. Could use some help here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So currently, wt -d c:\some\invalid\path will do this:

image

That's not a super useful error, ERROR_DIRECTORY - I guess that makes sense, though not totally obvious what's wrong here.

I'm okay with us leaving this for now. We do some validation of the startingDirectory on settings load, but nothing for directories passed as commandline args, and I think that's fine.

If we did want to try and pre-validate, we could pull Profile::EvaluateStartingDirectory into a helper, and only use the control's directory if it's valid. That's actually probably a good idea.

@zadjii-msft zadjii-msft self-assigned this Nov 20, 2020
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks pretty good. No major concerns - but I'm on the fence about validating the paths ahead of time. I want this to land, but maybe we should validate ahead of time.

I'll block for the discussion, but it's otherwise a fine PR

EDIT: I'm also blocking over the pane duplicating. We should probably do that.

@@ -1015,6 +1015,13 @@ namespace winrt::TerminalApp::implementation
if (profileGuid.has_value())
{
const auto settings{ winrt::make<TerminalSettings>(_settings, profileGuid.value(), *_bindings) };
const auto workingDirectory = terminalTab->GetActiveTerminalControl().WorkingDirectory();
const auto validWorkingDirectory = !workingDirectory.empty();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So currently, wt -d c:\some\invalid\path will do this:

image

That's not a super useful error, ERROR_DIRECTORY - I guess that makes sense, though not totally obvious what's wrong here.

I'm okay with us leaving this for now. We do some validation of the startingDirectory on settings load, but nothing for directories passed as commandline args, and I think that's fine.

If we did want to try and pre-validate, we could pull Profile::EvaluateStartingDirectory into a helper, and only use the control's directory if it's valid. That's actually probably a good idea.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 15, 2020
@zadjii-msft
Copy link
Member

As far as pane duplicating goes, that's down in TerminalPage::_SplitPane. Somewhere near:

            if (splitMode == SplitType::Duplicate)
            {
                std::optional<GUID> current_guid = focusedTab->GetFocusedProfile();
                if (current_guid)
                {
                    profileFound = true;
                    controlSettings = { winrt::make<TerminalSettings>(_settings, current_guid.value(), *_bindings) };
                    realGuid = current_guid.value();
                }

@zadjii-msft zadjii-msft removed their assignment Dec 15, 2020
@skyline75489
Copy link
Collaborator Author

Another thing that I'm not so sure: in #7668 I make both new-tab and duplicate-tab use the CWD. In this PR, I figured it's too aggresive so I changed it to just duplicate-tab. Is this too aggresive, or what people would want? Personally I'm OK with new-tab also accepting CWD but I'm not sure what others will feel about this.

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 16, 2020
@zadjii-msft
Copy link
Member

zadjii-msft commented Dec 16, 2020

I'd say let's just start with the duplicateTab action. We could probably consider adding an argument to newTab to allow it to duplicate paths as well. But that parameter can wait for a follow-up PR (let's just get this in to start with 😄). That's my opinion at least.

@skyline75489
Copy link
Collaborator Author

skyline75489 commented Dec 17, 2020

I've been thinking about the path validation, then it occurs to me that the OSC 9;9 feature is currently a super opt-in kind of things. Users will need to modify their shell script in order to even get this up and running. So I guess even if they have wrongly configured the path and be frustrated by the error when launching x.exe, they are likely to know the root cause of it is exactly the misconfiguration created by themselves. Besides, with only duplicateTab/Pane enabled now, there's little chance that a WSL path is passed to powershell.exe or vice versa, which considerably reduces the chances of misformated URLs being passed around across different profiles. So yeah I think this is ready now.

@skyline75489 skyline75489 marked this pull request as ready for review December 17, 2020 10:28
@zadjii-msft
Copy link
Member

Yea I'm fine with not path validating as well. Can we get this added to duplicating panes though too 😄?

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a derp, this does work with pane splitting too. So let's do this

@carlos-zamora carlos-zamora added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 11, 2021
@ghost
Copy link

ghost commented Jan 11, 2021

Hello @carlos-zamora!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit e557a86 into microsoft:main Jan 11, 2021
@skyline75489 skyline75489 deleted the chesterliu/dev/osc-9-9 branch January 25, 2021 02:57
mpela81 pushed a commit to mpela81/terminal that referenced this pull request Jan 28, 2021
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request

This PR implement the OSC 9;9 

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


<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> 
## References

microsoft#8214

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [X] Closes microsoft#8166
* [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
ghost pushed a commit that referenced this pull request Feb 4, 2021
This PR fixes the parsing of OSC 9;9 sequences with path surrounded by
quotation marks.

Original OSC 9;9 PR: #8330 

Unit test added. Manually tested with oh-my-posh.

Closes #8930
DHowett pushed a commit that referenced this pull request Feb 5, 2021
This PR fixes the parsing of OSC 9;9 sequences with path surrounded by
quotation marks.

Original OSC 9;9 PR: #8330

Unit test added. Manually tested with oh-my-posh.

Closes #8930

(cherry picked from commit 0811c57)
@tavrez
Copy link

tavrez commented Mar 2, 2021

I can't use this in todays releases anymore(both stable and preview). Something changed?

@skyline75489
Copy link
Collaborator Author

@tavrez No nothing changed I believe. Are you positive that you are using the "duplicate tab"(ctrl + shift + d) instead of "creating new tab" (ctrl + shift + t) ? If you have a consistent repro, feel free to open a new issue.

@tavrez
Copy link

tavrez commented Mar 2, 2021

Yes I'm using duplicate tab(with keyboard shortcut and from command pallete), It doesn't work, it goes back to starting directory. If you are not having this problem(simply open a new terminal, change directory, press duplicate tab) probably I'm doing something wrong(but this procedure worked for me in prev version it introduced in Terminal Preview)

@skyline75489
Copy link
Collaborator Author

@tavrez It's working for me. Sorry I guess you'll need to check the shell configuration you're using.

@LeaveTheCapital
Copy link

This does not work for me either in latest preview, or in latest Windows Terminal, when using duplicate tab (ctrl + shift + d). Am I missing something? Is there a setting that needs to be enabled?

@tavrez
Copy link

tavrez commented Mar 19, 2021

@LeaveTheCapital just to make sure, do you send the sequence code (ESC ] 9 ; 9 ; “cwd” ST) before duplicating? If yes, you probably has a weird problem like me, I can't use this only on my personal PC

@LeaveTheCapital
Copy link

@LeaveTheCapital just to make sure, do you send the sequence code (ESC ] 9 ; 9 ; “cwd” ST) before duplicating? If yes, you probably has a weird problem like me, I can't use this only on my personal PC

I did try this, however I must have been doing something wrong - perhaps someone could help with an idiots guide, or a link to similar? Thank you

@skyline75489
Copy link
Collaborator Author

@LeaveTheCapital You can try the gist to see if it helps. Make sure you are using "Duplicate Tab" (Ctrl+Shift+d, by default) and not "New Tab" (Ctrl + T)

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Second It's a PR that needs another sign-off Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider using OSC 9;9 to inform Windows Terminal about CWD
5 participants