You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
more and less take over the screen buffer so there's no way to display this info (unless we inject content into the help which would have to be at the top). Longer term, I believe there is discussion on having a built-in pager in PowerShell where we can provide more help and consistent experience.
Keith Hill (@rkeithhill) cool! Wasn't aware of this parameter for less. Is this consistent across distros? My experience is that different distros have different versions of native tools so not all of them have the same parameters/switches.
less is flexible enough to support this. It appears to me that more is not. One step at a time. :-) Also, consider that usage of PS Core is ~80% on non-Windows. So tweaking less to display this seems like it's worth doing. The other option is to wait on a PS specific paging utility or replacement to more on Windows. We may be waiting a while for these.
leave Windows users with a somewhat unclear prompt in comparison.
BTW, it's been that way for 12 years. For some reason I think it is less of an issue with more than with less. We integrated less into PSCX a long time ago and we definitely did get issues/complaints from folks who couldn't figure out how to exit less. Oh yeah, forgot to mention that you can run less on Windows. That's what I do. Just set $env:PAGER = 'less'. Since that env can supply args now I think you could set it to $env:PAGER = 'less "-PPowerShell help line %lt (press h for help or q to quit)"'. Of course, you need to grab less and stick in your path somewhere.
Reacted by Rain Sallow (/u/ta11ow) and Michael Klement
macOS, FreeBSD, and Linux distros (all? verified on Ubuntu) all seem to have the very same GNU implementation of less, so my guess is that it works on all supported Unix-like platforms.
This despite the fact that less is not a POSIX-mandated utility, only more is (which doesn't support prompt customization).
Small caveat: on macOS, more is less in disguise, so the man utility effectively uses less there, which means that customization of less via $env:LESS also affects man paging.
Even though on Ubuntu uses less by default too, it applies its own prompt-string customization, which overrides $env:LESS.
Small syntax correction: it should be -Ps"..", because the first char. after P indicates which prompt string is being customized (s for short (default), m for medium (with the -m option), M for long (with the -M option)).
Also, if multiple options must be preset in $env:LESS, the end of the prompt string must be marked with $.
Updated examples, which additionally show an example of a conditional token and the need to escape literal . as \. (alongside ? % \ :):
# Note the 's' after '-P' and the need to \-escape .# ?B of %D:. is a conditional that shows "of page <page-count>", if known, and nothing otherwise.
gps | less '-PsPage %db?B of %D:.\. Press h for help or q to quit\.'# Note the $ as the string terminator.$env:LESS='-PsPage %db?B of %D:.\. Press h for help or q to quit\.$'
gps | less
Activity
SteveL-MSFT commentedon Oct 10, 2018
moreandlesstake over the screen buffer so there's no way to display this info (unless we inject content into the help which would have to be at the top). Longer term, I believe there is discussion on having a built-in pager in PowerShell where we can provide more help and consistent experience.rkeithhill commentedon Oct 11, 2018
Actually, this can be done by PowerShell Core. Try this:
This gives a display of:

Ah, and you can get this now (no changes to PS Core) by setting this env var:
SteveL-MSFT commentedon Oct 11, 2018
Keith Hill (@rkeithhill) cool! Wasn't aware of this parameter for
less. Is this consistent across distros? My experience is that different distros have different versions of native tools so not all of them have the same parameters/switches.rkeithhill commentedon Oct 11, 2018
This is where man defines the prompt string - https://git.savannah.gnu.org/cgit/man-db.git/tree/src/man.c#n4184 This source is used in quite a few distributions according to the home page - http://man-db.nongnu.org/
vexx32 commentedon Oct 11, 2018
That's great for Linux, but does leave Windows users with a somewhat unclear prompt in comparison. 😕
rkeithhill commentedon Oct 11, 2018
lessis flexible enough to support this. It appears to me thatmoreis not. One step at a time. :-) Also, consider that usage of PS Core is ~80% on non-Windows. So tweakinglessto display this seems like it's worth doing. The other option is to wait on a PS specific paging utility or replacement tomoreon Windows. We may be waiting a while for these.BTW, it's been that way for 12 years. For some reason I think it is less of an issue with
morethan withless. We integratedlessinto PSCX a long time ago and we definitely did get issues/complaints from folks who couldn't figure out how to exitless. Oh yeah, forgot to mention that you can runlesson Windows. That's what I do. Just set$env:PAGER = 'less'. Since that env can supply args now I think you could set it to$env:PAGER = 'less "-PPowerShell help line %lt (press h for help or q to quit)"'. Of course, you need to grablessand stick in your path somewhere.mklement0 commentedon Oct 11, 2018
Indeed, handy stuff.
macOS, FreeBSD, and Linux distros (all? verified on Ubuntu) all seem to have the very same GNU implementation of
less, so my guess is that it works on all supported Unix-like platforms.This despite the fact that
lessis not a POSIX-mandated utility, onlymoreis (which doesn't support prompt customization).Small caveat: on macOS,
moreislessin disguise, so themanutility effectively useslessthere, which means that customization oflessvia$env:LESSalso affectsmanpaging.Even though on Ubuntu uses
lessby default too, it applies its own prompt-string customization, which overrides$env:LESS.Small syntax correction: it should be
-Ps"..", because the first char. afterPindicates which prompt string is being customized (sfor short (default),mfor medium (with the-moption),Mfor long (with the-Moption)).Also, if multiple options must be preset in
$env:LESS, the end of the prompt string must be marked with$.Updated examples, which additionally show an example of a conditional token and the need to escape literal
.as\.(alongside? % \ :):For more on prompt-string syntax, see https://man.cx/less#heading10