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

Setting Powershell as default terminal for Windows 10+ (fixes #16838) #18493

Merged

Conversation

jchadwick
Copy link
Contributor

@jchadwick jchadwick commented Jan 13, 2017

Resolves #16838

@Tyriar Tyriar self-assigned this Jan 13, 2017
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

Just a few comments, I restarted the Travis build as it looked like it was flaky.

import platform = require('vs/base/common/platform');
import processes = require('vs/base/node/processes');

const powershellPath = `${ process.env.SystemRoot }/system32/WindowsPowerShell/v1.0/powershell.exe`;
Copy link
Member

Choose a reason for hiding this comment

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

I think sysnative/ should be used on 64 bit machines? Please confirm @daviwil

Copy link
Contributor

Choose a reason for hiding this comment

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

That is correct. Since VS Code is a 32-bit process, the 64-bit version of PowerShell has to be explicitly launched otherwise you'll get the 32-bit version. Here's the relevant code from the PowerShell extension:

https://github.com/PowerShell/vscode-powershell/blob/5b32676e9559233f8759e3b0c60583c60e70eb94/src/session.ts#L493

@@ -17,7 +17,7 @@ export const TERMINAL_SERVICE_ID = 'terminalService';

export const TERMINAL_DEFAULT_SHELL_LINUX = !platform.isWindows ? (process.env.SHELL || 'sh') : 'sh';
export const TERMINAL_DEFAULT_SHELL_OSX = !platform.isWindows ? (process.env.SHELL || 'sh') : 'sh';
export const TERMINAL_DEFAULT_SHELL_WINDOWS = processes.getWindowsShell();
/** const TERMINAL_DEFAULT_SHELL_WINDOWS moved to ../electron-browser/terminal.ts */
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this line 👍

import processes = require('vs/base/node/processes');

const powershellPath = `${ process.env.SystemRoot }/system32/WindowsPowerShell/v1.0/powershell.exe`;
const isAtLeastWindows10 = platform.isWindows && parseFloat(os.release()) >= 10;
Copy link
Member

Choose a reason for hiding this comment

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

I think you'd be better off getting the major version here as os.release() may return x.y.z?

Something like this should be safe (if Node does indeed give that format):

parseInt(os.release().split('.')[0], 10) >= 10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if it's necessary, since I'm parsing it to a float. That means 10.2.22222 and 11.4.4444 will still be >= 10 (and 9.5.555 will not).

I'm happy to take the change - let me know what you want to do.

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be best to be explicit here, parseFloat('10.2.22222') may work but it feelss dodgy to me and the behavior itself may even be undefined and only works by coincidence.

@daviwil
Copy link
Contributor

daviwil commented Jan 13, 2017

Thanks for sending this out, @jchadwick!

@jchadwick jchadwick force-pushed the jchadwick/default-powershell-terminal branch from 33cb4c7 to 74aee4a Compare January 14, 2017 01:34
@jchadwick
Copy link
Contributor Author

@Tyriar I think that I incorporated all your feedback. Not sure what's going on with the Travis build, but I think I'm all good here.

import processes = require('vs/base/node/processes');

const powerShellExePath =
!process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')
Copy link
Member

Choose a reason for hiding this comment

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

@daviwil so this is an env variable only available on 64 bit Windows? Would it be better to check process.arch instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dunno, I just copied from the PowerShell extension. :-D

process.arch probably makes more sense anyway. I'll change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, now that I'm playing around with it, process.arch is going to give you 32-bit. I think that code that I stole from @daviwil is probably the right way to do it.

Copy link
Contributor

@daviwil daviwil Jan 14, 2017

Choose a reason for hiding this comment

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

Yep, that's what I had to use to figure out the true bitness of the OS.

@Tyriar
Copy link
Member

Tyriar commented Jan 15, 2017

Great, thanks @jchadwick 😄

@Tyriar Tyriar merged commit cd17a28 into microsoft:master Jan 15, 2017
@Tyriar Tyriar added this to the January 2017 milestone Jan 15, 2017
@jchadwick jchadwick deleted the jchadwick/default-powershell-terminal branch February 3, 2017 19:41
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows PowerShell should be the default terminal program on Windows
4 participants