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

Remove 'more' function and move the $env:PAGER capability into the help function #6059

Merged
merged 13 commits into from May 4, 2018
47 changes: 16 additions & 31 deletions src/System.Management.Automation/engine/InitialSessionState.cs
Expand Up @@ -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

Expand All @@ -4262,7 +4266,16 @@ .FORWARDHELPCATEGORY Cmdlet
}
else
{
$help | more
# Respect PAGER, use more on Windows, and use less on Linux
if (Test-Path env:PAGER) {
$moreCommand = (Get-Command -CommandType Application $env:PAGER | Select-Object -First 1).Definition
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will lose the ability to specify arguments to the pager utility - $pager,$moreArgs = $env:PAGER -split '\s+' . That doesn't bother me personally but presumably somebody added these for a reason (an issue I suspect).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that was explicitly to fix #6142

Should just use the same code as from https://github.com/PowerShell/PowerShell/pull/6144/files

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the reminder!

Fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it possible to add tests to exclude such regression?

} 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
}
";
}
Expand Down Expand Up @@ -4743,32 +4756,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";
Expand All @@ -4780,8 +4767,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
Expand Down
4 changes: 0 additions & 4 deletions test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Expand Up @@ -529,8 +529,4 @@ Describe "Verify approved aliases list" -Tags "CI" {
$result | Write-Host
$result | Should -BeNullOrEmpty
}

It "Should have 'more' as a function" {
Test-Path Function:more | Should -BeTrue
}
}