Skip to content

[request] prompt expansion to line content #790

Description

@avih

Prompt string %bX and several others expand to line/page/percentage/etc of the top/mid/bot/target line, depending on X.

This is a request to do the same as far as identifying the line, but expand to the actual line content.

This can be useful with external commands which can perform some action depending on the line content, like extracting a git hash from the line, and running git show HASH, etc.

I expect it would be most useful with external commands rather than in an actual "less" prompt, so it likely needs to be shell-quoted.

It might be debatable whether the value should be the displayed value (for instance with some binary escaped) or the actual input line content, whether it should be the full line or only the visible part (in case it's cropped or wrapped to the next page).

I think the simplest and probably most useful is the full original unmodified input line, including binaries and parts of it which are not on-screen, if any.

One exception to "full original line" might be byte value 0 - which will likely cause issues on many platforms if it appears at the middle of an argument, but it's not obvious to me what to do with 0 byte in such case (removing it is an option, but it feels meh). Or maybe replace byte 0 with newline? (because a single line doesn't include newlines by definition, so there's no ambiguity).

Off topic, but it could also be used to test shell quoting of arbitrary values using an input file which was crafted for such test, probably including 0 byte too.

EDIT: it's possible to do that with line number and the original file name (so that the external command can extract that line from the file on its own), but that wouldn't work for content from stdin.

EDIT2: another option instead of expanding it to a line-content argument is to send the line to an external command's stdin (maybe with other arguments, which could also be other prompt expansions). In such case it can include 0 bytes, and it's up to the external utility to handle it as it sees fit. That would not allow testing shell-quoting though, but it's not the goal of this feature to begin with.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions