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
I’d like to be able to pass less’s current cursor position to shell commands. I can achieve the functionality I want using less’s pipe command and wc -c/wc -l, but having less pipe a bunch of data to a program that’s going to throw it away seems kludgey. less knows where the cursor is and tells text editors directly; it would be nice if it could tell arbitrary other programs too. Unfortunately, just adding prompt expansion to shell seems like a poor idea, since it conflicts with less’s current behavior of expanding % to the active file. I can think of a few other ways forward, but I’m not sure which one is the best way for less.
One option is to change less to export cursor position data in an environment variable. For example, less could invoke shell commands with a variable setting like LESS_POSITION=37:309, where the two numbers are the current line and byte offset, respectively. Polluting the environment like this seems a little unfortunate, but it is simple and backward compatible, and perhaps it wouldn’t be so bad if it were behind a flag.
Another option is to introduce a new command (pshell?) that acts like shell but expands prompt strings rather than % and #. This is more complex, but it’s also probably more useful, since users could use it to pass whatever prompt expansions they want to shell commands, rather than just cursor information.
The text was updated successfully, but these errors were encountered:
I’d like to be able to pass less’s current cursor position to shell commands. I can achieve the functionality I want using less’s pipe command and
wc -c
/wc -l
, but having less pipe a bunch of data to a program that’s going to throw it away seems kludgey. less knows where the cursor is and tells text editors directly; it would be nice if it could tell arbitrary other programs too. Unfortunately, just adding prompt expansion toshell
seems like a poor idea, since it conflicts with less’s current behavior of expanding%
to the active file. I can think of a few other ways forward, but I’m not sure which one is the best way for less.One option is to change less to export cursor position data in an environment variable. For example, less could invoke shell commands with a variable setting like
LESS_POSITION=37:309
, where the two numbers are the current line and byte offset, respectively. Polluting the environment like this seems a little unfortunate, but it is simple and backward compatible, and perhaps it wouldn’t be so bad if it were behind a flag.Another option is to introduce a new command (
pshell
?) that acts likeshell
but expands prompt strings rather than%
and#
. This is more complex, but it’s also probably more useful, since users could use it to pass whatever prompt expansions they want to shell commands, rather than just cursor information.The text was updated successfully, but these errors were encountered: