-
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
How can I determine if my PowerShell script is running in Windows terminal? #6269
Comments
This is working for me:
|
Great,3q alot! |
@kasini3000 @marvhen I think it's considerably easier to check for the existence of the function Test-WindowsTerminal { test-path env:WT_SESSION }
# or
if ($env:WT_SESSION) {
# yes, windows terminal
} else {
# nope
} |
Indeed...much easier. I was not aware of that variable, but now see it is documented here. |
So I too initially headed down the route of checking function Test-IsEmojiFriendly {
if ("$OutputEncoding".EndsWith('UTF8Encoding')) {
return $true
}
return $false
} There are probably other terminal-specific considerations here, but hopefully this helps. |
That's just going to tell you if PowerShell thinks it can send UTF-8 data somewhere; it will not tell you anything about the capabilities of the terminal it's talking to. |
FYI. I just rewrote |
This commit deletes the is_Windows_Terminal funcref added in 6390072; The lambda's definition was incorrect, e.g. after starting "Command Prompt" from the Windows 11 Start Menu the lambda would return false even when Windows Terminal was being used. (See microsoft/terminal#13006. microsoft/terminal#6269 (comment) claims to have code to check whether a program is running in Windows Terminal or not.) There may be some Windows terminal programs that only support 16 colors, but that's not relevant to me.
This comment was marked as off-topic.
This comment was marked as off-topic.
That returns true if any instance of WindowsTerminal is running. PowerShell could be running on an old Console Host and still return true if a WT is open. |
Thanks. Do you have a 100% valid method? Looking for $Env:WT_SESSION not valid too |
How can I determine if my PowerShell script is running in Windows terminal?
I wrote a script, a.ps1, which contains some special unicode characters.
I want to check whether my script is running in the powershell executed by windows terminal. How can I detect the windows terminal host?
The text was updated successfully, but these errors were encountered: