PowerShell should display how to exit out of more
or less
.
See man
in Bash (man top
):
Current PowerShell functionality (help get-process
):
This leaves unfamiliar users unaware on how to exit.
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.
Actually, this can be done by PowerShell Core. Try this:
get-help gps -full | less -P"PowerShell help page line %lt (press h for help or q to quit)"
This gives a display of:
Ah, and you can get this now (no changes to PS Core) by setting this env var:
$env:LESS = "-PPowerShell help page line %lt (press h for help or q to quit)"
@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.
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/
That's great for Linux, but does leave Windows users with a somewhat unclear prompt in comparison. 馃槙
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 tweakingless
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.
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 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
For more on prompt-string syntax, see https://man.cx/less#heading10
Most helpful comment
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: