-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
set identifying environment variable for new connections #897
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks really good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool. Thanks for doing it!
I'm not 100% comfortable signing off, as I'd like @zadjii-msft and @adiviness to give it a twice-over, but I'm also not going to block.
Set a new 'WT_SESSION' environment variable when creating new terminal connections to allow shells to detect a unique Windows Terminal session. The value of the variable is a stringified GUID as returned by CoCreateGuid. How verified: - "razzle" & vs debug build - runut - manual inspection
* use Utils::GuidToString for guid stringification * expose guid parameter in ITerminalConnection idl
- misc. review fixes - throw if CreateConPty fails in ConhostConnection::Start - apply [[nodiscard]] and noexcept in various places
@@ -57,27 +62,41 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation | |||
|
|||
void ConhostConnection::Start() | |||
{ | |||
std::wstring cmdline = _commandline.c_str(); | |||
std::wstring cmdline{ _commandline.c_str() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer std::wstring cmdline{ _commandline.begin(), _commandline.end() };
because then we get guarantees about the bounds o the string we're using to initialize and we don't need to dip into the behind-the-scenes data members of std::string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string has an explicit constructor from a T
that has a data and size; maybe it can be used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(std::wstring cmdline{_commandline}
)
I am willing to push this with the nits outstanding. @adiviness, would you block on #897 (comment)? |
naw, it's probably ok. We can always fix it later as well. |
@binarycrusader thanks so much for doing this. 👍 |
To reproduce, press the Windows key to open start, then type This now opens a Windows Terminal cmd.exe tab via |
Since v0.1.1431.0, Windows Terminal sets `WT_SESSION` environment variable that we may use to detect it. > See <microsoft/terminal#897> `TERM_PROGRAM` is not supported (yet ?). > See <microsoft/terminal#1828>
Right 😢 Also see #13006. |
Summary of the Pull Request
Set a WT_SESSION environment variable to a unique guid on every new connection to allow shell consumers to detect Windows Terminal and uniquely identify the session.
References
Unknown.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Set a new 'WT_SESSION' environment variable when creating new terminal connections to allow shells to detect a unique Windows Terminal session. The value of the variable is a stringified GUID as returned by
CoCreateGuid.
How verified:
Uncertain about what tests to add and where; all of the existing ones passed.
I did some basic research to try to ensure that "WT_SESSION" is a "unique", non-conflicting environment variable and so shouldn't cause any problems with any existing programs. I'm certainly open to suggestions about the name though.