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

Run any command when clicking on a link matching a regexp #3791

Open
nojhan opened this issue May 28, 2023 · 2 comments
Open

Run any command when clicking on a link matching a regexp #3791

nojhan opened this issue May 28, 2023 · 2 comments
Labels
docs Primarily or only affects documentation

Comments

@nojhan
Copy link

nojhan commented May 28, 2023

I want to be able to open a file at a specific line in my IDE, just by clicking on an error message in my terminal.

For instance, for opening a python script indicated in a python error, within Vim, I would use configure the following option:

regexp = \B(/\S+?\.py)\S{2}\sline\s(\d+)
command = gvim --servername IDE --remote +$1 $0

For command such as "open in a [web|file] browser", the hyperlink_rules feature already does the job. But if one want to trigger just any command, it cannot work, as it is limited to a predefined set of protocols.

At least URxvt and Terminator have this feature. I implemented it in Terminator, by using the existing link handler, and allow adding a terminator:// protocol, that bypass xdg-open and run the configured command. This had the minimum footprint and reused the existing link handling code.

Example

Run a script that display the info to catch, here a Python script displaying THE ABSOLUTE PATH.

echo "print('What the F)" >  test.py
python3 $(pwd)/test.py

Note that if you just do ./test.py, then the path information is contextual and it's not going to work (or else we would need to pass the current directory from the shell to the URL manager). In that case, the observed behaviour would be to open an empty file.

Then, you have to pass the mouse over the path segment to see it underlined, and [Ctrl-] click to open it.

Example (the mouse is over the link):

@nojhan nojhan added the enhancement New feature or request label May 28, 2023
@wez wez added docs Primarily or only affects documentation and removed enhancement New feature or request labels May 28, 2023
@wez
Copy link
Owner

wez commented May 28, 2023

@nojhan
Copy link
Author

nojhan commented Jun 28, 2023

Thanks. That's actually 118 lines of code with several config entry points for the user to maintain. Is there any chance that such a useful feature would be included in the codebase at some point?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Primarily or only affects documentation
Projects
None yet
Development

No branches or pull requests

2 participants