PSCore6 automatically loads PSReadline when the console is interactive. There is currently no option to not load it (other than deleting PSReadline). We should have a switch to allow not auto-loading PSReadline.
I can work on this one. Is there a recommended approach to writing tests for these switches?
@DdWr awesome! Take a look at https://github.com/PowerShell/PowerShell/blob/master/test/powershell/Host/ConsoleHost.Tests.ps1 and it should be pretty straight forward on adding tests for this.
For now, I guess you can use the switch -NoPSReadline
cc @lzybkr @joeyaiello
hmm -NoPSReadline
would break the commonly use -NoP
shortcut for -NoProfile
I was thinking of an environment variable instead of a command line switch.
This would be less annoying than remembering a switch, but would make one off experiments harder.
Note that PSReadline is not loaded when you specify -NonInteractive
. This option is for those few people where they just don't like PSReadline or it's causing some sort of problem.
I'm a little hesitant about adding such a "specific" switch. If PowerShell auto-loads more modules in the future, then you're signing yourself up to add more switches for each module. You can always add rmo psreadline
to your profile script since that is primarily what a profile is for - customizing your interactive environment. An environment variable would be OK as well.
Maybe a more general approach would be to add an -InitializationScript
parameter e.g.:
powershell -init {rmo psreadline}
@rkeithhill the problem with -initializationscript
is that you incur the cost of loading psreadline and then unloading it. We had some issues in the past with psreadline on NanoServer (which we have since fixed), but the workaround at that time was to delete psreadline to get powershell to startup. PSReadline as a module is special cased as we decided it was the interactive experience we wanted consistently in Windows Powershell and retained it for PowerShell Core 6.
In general, I'm not a fan of having an env var as it makes it less discoverable and I expect most users to use PSReadline.
@SteveL-MSFT Fair point on loading and then unloading. Although if you expect most users to use PSReadline, then the user scenario of disabling PSReadline is a bit of a corner case. So making it possible is probably enough and folks will discover it through an internet search. And it wouldn't be the first env var PowerShell uses. We already have PSModulePath and PAGER to configure PowerShell. Also, for temp use it isn't a big deal to do:
$env:PSDisablePSReadline=1
powershell.exe
I think using the PowerShell profile would be a better way to handle the PSReadLine than doing a drastic code change. You can always go back and remove the 'Remove-Module PSReadLine' at your discretion.
:)
@SteveL-MSFT I'm assuming this is still in the review queue? :)
Yes, we had too many to review at the last meeting and didn't get to this.
Originally, I saw this as a good "step 1" to "the grand refactor" we've been talking about to optimize for non-interactive scenarios, but if -NonInteractive
already does that, I don't see a need for an additional switch. Remove-Module PSReadline
in your profile seems like a good enough solution there, though it'd be easier to assess if we had perf stats on loading PSReadline.
@joeyaiello -NonInteractive
doesn't solve the case where you want interactive, but not PSReadline. Remove-Module PSReadline
is not a good solution as I believe generally people want PSReadline (since the built-in readline now is by-design very primitive), but there are some cases where things don't work well with PSReadline enabled (ssh, ShellInABox, etc...).
For me, it seems the simplest thing is to add a -nopsreadline
switch.
So we speak about interactive session I'd prefer Remove-Module in profile or an option in config file.
If anybody don't want at all it is possible to uninstall the module.
@PowerShell/powershell-committee doesn't think this is needed as for non-interactive, PSReadline doesn't load, in other cases, one can use -c { rmo psreadline} -noexit
to unload it for an interactive session or put it in $profile to unload it on start.
Most helpful comment
I was thinking of an environment variable instead of a command line switch.
This would be less annoying than remembering a switch, but would make one off experiments harder.
Note that PSReadline is not loaded when you specify
-NonInteractive
. This option is for those few people where they just don't like PSReadline or it's causing some sort of problem.