From bd03b51c32a96ae7191f85fc2b886d76e1d35b52 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 21:20:57 -0700 Subject: [PATCH] Respect PAGER variable and default to less on Linux --- .../engine/InitialSessionState.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 1eb0e80bbb..c38707f96e 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -5475,10 +5475,18 @@ end internal const string DefaultMoreFunctionText = @" param([string[]]$paths) $OutputEncoding = [System.Console]::OutputEncoding -$moreCommand = (Get-Command -CommandType Application more).Definition | Select-Object -First 1 + +# Respect PAGER, use more on Windows, and use less on Linux +if (Test-Path env:PAGER) { + $moreCommand = (Get-Command -CommandType Application $env:PAGER).Definition | Select-Object -First 1 +} elseif ($IsWindows) { + $moreCommand = (Get-Command -CommandType Application more).Definition | Select-Object -First 1 +} else { + $moreCommand = (Get-Command -CommandType Application less).Definition | Select-Object -First 1 +} + if($paths) { - foreach ($file in $paths) - { + foreach ($file in $paths) { Get-Content $file | & $moreCommand } } else { $input | & $moreCommand }