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
Remove 'more' function and move the $env:PAGER capability into the help function #6059
Changes from 10 commits
87c24d8
83f241d
e6c11fd
641c5a4
09a6bdf
3cc2c84
7a3b9f4
a9b72eb
b25acd9
bdee0ec
a792bd4
31ab358
b6f60be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4250,8 +4250,12 @@ .FORWARDHELPCATEGORY Cmdlet | |
$PSBoundParameters['Full'] = $true | ||
} | ||
|
||
# Set the outputencoding to Console::OutputEncoding. More.com doesn't work well with Unicode. | ||
$outputEncoding=[System.Console]::OutputEncoding | ||
# Nano needs to use Unicode, but Windows and Linux need the default | ||
$OutputEncoding = if ([System.Management.Automation.Platform]::IsNanoServer -or [System.Management.Automation.Platform]::IsIoT) { | ||
[System.Text.Encoding]::Unicode | ||
} else { | ||
[System.Console]::OutputEncoding | ||
} | ||
|
||
$help = Get-Help @PSBoundParameters | ||
|
||
|
@@ -4262,7 +4266,17 @@ .FORWARDHELPCATEGORY Cmdlet | |
} | ||
else | ||
{ | ||
$help | more | ||
# Respect PAGER, use more on Windows, and use less on Linux | ||
if (Test-Path env:PAGER) { | ||
$pager,$moreArgs = $env:PAGER -split '\s+' | ||
$moreCommand = (Get-Command -CommandType Application $pager | Select-Object -First 1).Definition | ||
} elseif ($IsWindows) { | ||
$moreCommand = (Get-Command -CommandType Application more | Select-Object -First 1).Definition | ||
} else { | ||
$moreCommand = (Get-Command -CommandType Application less | Select-Object -First 1).Definition | ||
} | ||
|
||
$help | & $moreCommand $moreArgs $moreArgs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not only in your post, that's also the case in your code change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to do rebase but I wanted to keep the commit history. As a result lost the essence. The code was refactored. |
||
} | ||
"; | ||
} | ||
|
@@ -4743,32 +4757,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases | |
# .Link | ||
# https://go.microsoft.com/fwlink/?LinkID=225750 | ||
# .ExternalHelp System.Management.Automation.dll-help.xml | ||
"; | ||
|
||
internal const string DefaultMoreFunctionText = @" | ||
param([string[]]$paths) | ||
# Nano needs to use Unicode, but Windows and Linux need the default | ||
$OutputEncoding = if ([System.Management.Automation.Platform]::IsNanoServer -or [System.Management.Automation.Platform]::IsIoT) { | ||
[System.Text.Encoding]::Unicode | ||
} else { | ||
[System.Console]::OutputEncoding | ||
} | ||
|
||
# Respect PAGER, use more on Windows, and use less on Linux | ||
if (Test-Path env:PAGER) { | ||
$pager,$moreArgs = $env:PAGER -split '\s+' | ||
$moreCommand = (Get-Command -CommandType Application $pager | Select-Object -First 1).Definition | ||
} elseif ($IsWindows) { | ||
$moreCommand = (Get-Command -CommandType Application more | Select-Object -First 1).Definition | ||
} else { | ||
$moreCommand = (Get-Command -CommandType Application less | Select-Object -First 1).Definition | ||
} | ||
|
||
if($paths) { | ||
foreach ($file in $paths) { | ||
Get-Content $file | & $moreCommand $moreArgs | ||
} | ||
} else { $input | & $moreCommand $moreArgs } | ||
"; | ||
|
||
internal const string DefaultSetDriveFunctionText = "Set-Location $MyInvocation.MyCommand.Name"; | ||
|
@@ -4780,8 +4768,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases | |
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("prompt", DefaultPromptFunctionText, isProductCode: true), | ||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("TabExpansion2", s_tabExpansionFunctionText, isProductCode: true), | ||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Clear-Host", GetClearHostFunctionText(), isProductCode: true), | ||
// Porting note: we keep more because the function acts correctly on Linux | ||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("more", DefaultMoreFunctionText, isProductCode: true), | ||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("help", GetHelpPagingFunctionText(), isProductCode: true), | ||
// Porting note: we remove mkdir on Linux because it is a conflict | ||
#if !UNIX | ||
|
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.
IIRC someone (@BrucePay) had initialized
$moreArgs
to an empty string above the preceding if/else statements to prevent a strict mode failure ($moreArgs not being defined when $env:PAGER is not defined).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.
#6781
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.
What about
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.
You have
$moreArgs
listed twice after the invocation of$moreCommand
. There should only be one.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 updated my post.
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.
Also, watch out for
$pager != $null
. That should be-ne
. That said, this line:Will assign an empty string, not
$null
, to $pager when$env:PAGER
is not defined. So I think the test should be simply:if ($pager)
. And ideally, ifget-command
can't find the app referred to by $env:PAGER, it should revert back to the default for the OS. Otherwise, you're left with a $null in $moreCommand andhelp | & $null
will fail.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.
Why are we doing
Get-Command -CommandType Application
? We get the same error forbadapp
,& badapp
andGet-Command -CommandType Application badapp
.