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 displaying files and commits as OSC 8 hyperlinks #257

Closed
dandavison opened this issue Jul 17, 2020 · 6 comments · Fixed by #261
Closed

🚀 Support displaying files and commits as OSC 8 hyperlinks #257

dandavison opened this issue Jul 17, 2020 · 6 comments · Fixed by #261

Comments

@dandavison
Copy link
Owner

dandavison commented Jul 17, 2020

This proposal introduces a spec for displaying hyperlinks in terminal emulators. Support for it among terminal emulators is already good, with more pending. Unfortunately neither less -R nor tmux support it yet, so for now Delta users would only be able to benefit by (a) using a fork of less (and tmux), or (b) not using less (or tmux) with delta.

In any case, two ways in which delta could make use of this feature are

  1. Format file names as clickable file:// links.
  2. Format commit hashes as links to an appropriate page in a git web-hosting site, if that is discernible from the git remote in the repo in which delta was invoked.

Both these would be optimistic: delta just receives text on stdin and there's no guarantee that the files in that text have ever existed anywhere! Also delta doesn't need to be invoked inside a git repo, and I think perhaps neither type of link-formatting should be done when delta is not invoked inside a git repo.

dandavison added a commit that referenced this issue Jul 17, 2020
dandavison added a commit that referenced this issue Jul 17, 2020
dandavison added a commit that referenced this issue Jul 18, 2020
dandavison added a commit that referenced this issue Jul 18, 2020
dandavison added a commit that referenced this issue Jul 20, 2020
dandavison added a commit that referenced this issue Jul 22, 2020
dandavison added a commit that referenced this issue Jul 22, 2020
@navarroaxel
Copy link
Contributor

navarroaxel commented Jul 23, 2020

I tried to use git config --global delta.hyperlinks true without your less patch and the result was the expected:
Screenshot_20200722_221909
Screenshot_20200722_221959

But I tested your patch in less, first using the stable v551 and then the beta v563.

These are the Arch Linux's PKGBUILD files for less with your patch, and git-delta with the latest commit in master: https://gist.github.com/navarroaxel/40fea15bae01d6ffb0d2d4109474bdf1.

the result, with or without the delta.line-numbers=true was the same:
Screenshot_20200722_224000
Screenshot_20200722_224554

I'm using KDE's Konsole as my main terminal, and XTerm, but the line numbers or the filename is not a link. What I'm doing wrong? or the Konsole terminal doesn't support this?

@dandavison
Copy link
Owner Author

@navarroaxel Can you try with a terminal emulator that definitely supports the hyperlinks? Based on the links in https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda I fear that Konsole does not yet.

@navarroaxel
Copy link
Contributor

navarroaxel commented Jul 23, 2020

Works in a Konsole's PR still not merged!

Screenshot_20200723_084951

But don't open the editor in the line I clicked, should you add #position=line?

Could you add support for commit SHA links to GitLab or custom GitLab servers? like https://invent.kde.org/utilities/konsole/-/commit/f8e06d55a2d2a7e322cc980052aa86d67d3aae17

@dandavison
Copy link
Owner Author

dandavison commented Jul 23, 2020

But don't open the editor in the line I clicked, should you add #position=line?

Hi @navarroaxel (cc @Kr1ss-XD), this is discussed in the help text for the hyperlinks-file-link-format option. Basically file:// URLs simply do not support opening at a line number: the spec doesn't contain any place to put the line number, and text editors/IDEs have different syntax for requesting that they open at a line. So, what I am doing is

  1. Change the format of the file URLs emitted by delta
    [delta]
        hyperlinks-file-link-format = "file-line-column://{path}:{line}"

That's a custom URL scheme that I just made up for my use. So it will emit URLs that look like the common (but non-standardized) "compiler output format", but with URL syntax, and without column number: e.g. file-line-column:///home/dan/file.rs:77

  1. Configure an application to act as the URL handler for those URLs, and open the line in a text editor. For this I have written a small utility: https://github.com/dandavison/open-in-editor since I couldn't see something that did what I wanted for multiple text editors.

The utility currently supports opening in VSCode, Sublime, Emacsclient and PyCharm, and has instructions for registering the URL handler in MacOS.

If you can see a more streamlined way for delta users to do this, please let me know! (what supports #position=line?) Alternatively, if you would like to use open-in-editor then I'd appreciate any instructions for registering the application as the URL handler in Linux. And support for more editors could easily be added to the python script (e.g. I'm not sure exactly what behavior vim users would want).

Could you add support for commit SHA links to GitLab or custom GitLab servers?

Yeah, I was lazy and only added GitHub so far, I'll do GitLab! So that would be URLs of the format https://gitlab.com/gnachman/iterm2/-/commit/4600e60a0494d630ac25a277940bbd6359d89565, correct? Do you have an example of what the URL would look like for a custom GitLab server? The information delta is using is the git remote URL (remote.origin.url).

@dandavison
Copy link
Owner Author

Could you add support for commit SHA links to GitLab or custom GitLab servers? like https://invent.kde.org/utilities/konsole/-/commit/f8e06d55a2d2a7e322cc980052aa86d67d3aae17

@navarroaxel almost a year later but your suggestion is now implemented on master (there'll be a release soon). See #613

@navarroaxel
Copy link
Contributor

Thanks awesome @dandavison! 🤩 I'll test it sooner

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

Successfully merging a pull request may close this issue.

2 participants