Skip to content

Display how to exit more, less, etc #7988

Closed

Description

PowerShell should display how to exit out of more or less.

See man in Bash (man top):
image

Current PowerShell functionality (help get-process):
image

This leaves unfamiliar users unaware on how to exit.

Activity

  1. SteveL-MSFT commented on Oct 10, 2018

    @SteveL-MSFT
    Member

    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.

  2. added
    WG-Interactive-HelpSystem
    on Oct 10, 2018
  3. rkeithhill commented on Oct 11, 2018

    @rkeithhill
    Collaborator

    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:
    image

    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)"
    
  4. SteveL-MSFT commented on Oct 11, 2018

    @SteveL-MSFT
    Member

    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.

  5. rkeithhill commented on Oct 11, 2018

    @rkeithhill
    Collaborator

    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/

  6. vexx32 commented on Oct 11, 2018

    @vexx32
    Collaborator

    That's great for Linux, but does leave Windows users with a somewhat unclear prompt in comparison. 😕

  7. rkeithhill commented on Oct 11, 2018

    @rkeithhill
    Collaborator

    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.

  8. mklement0 commented on Oct 11, 2018

    @mklement0
    Contributor

    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

  9. added
    Issue-Discussion
    on Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-DiscussionResolution-FixedWG-Interactive-HelpSystem

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions