Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support byte and line offsets in shell commands #330

Closed
bbarenblat opened this issue Jan 29, 2023 · 2 comments
Closed

Support byte and line offsets in shell commands #330

bbarenblat opened this issue Jan 29, 2023 · 2 comments

Comments

@bbarenblat
Copy link

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.

@gwsw
Copy link
Owner

gwsw commented Jan 31, 2023

I think adding a new pshell command fits better into the way things already work. A new "#" command is implemented in e97ccd3.

@bbarenblat
Copy link
Author

This looks great – thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants