Skip to content

Option to print file paths as file URLs #665

Closed

Description

@sanmai-NL

Printing file paths as file URLs is very handy since you can click on them and the file will open. This happens in Konsole at least.

Activity

  1. BurntSushi commented on Nov 6, 2017

    @BurntSushi
    Owner

    Do other command line tools have an option like this? I don't think I've seen anything like it.

  2. added
    questionAn issue that is lacking clarity on one or more points.
    on Nov 6, 2017
  3. sanmai-NL commented on Nov 7, 2017

    @sanmai-NL
    Author

    @BurntSushi: I don't know off the top of my head. You also encounter such such links while paging log output, for example.

    To be clear, this isn't a question but a feature request. 🙂

    Similar feature requests

    Added value

  4. kpp commented on Nov 23, 2017

    @kpp
    Sponsor
    echo -e "/path1\n/path2" | xargs -n1 -I{} echo file://{}
    file:///path1
    file:///path2
    

    You may do the same for rg without modifying it.

  5. BurntSushi commented on Jan 31, 2018

    @BurntSushi
    Owner

    I think I'm going to close this. I don't see a lot of other tools doing this, and it should be possible to write a wrapper script to do this for you if you really want it.

  6. adrianocr commented on Jul 22, 2019

    @adrianocr

    I think this should be reopened and properly considered. Its insanely useful. Certain terminal apps such as iterm2 does it by default. But it could work across ALL of them if rg outputted links with the file:// syntax.

  7. alex commented on Jun 28, 2020

    @alex

    @BurntSushi I am not quite sure how this is implemented, but I just learned that ls has a feature ls --hyperlink=auto (or always or never), which causes it to emit things with ANSI shell magic that makes them clickable links in my terminal. Here's an example:

    alexgaynor@penguin ~/p/step-expirements> ls --hyperlink=always example.py
    example.py
    alexgaynor@penguin ~/p/step-expirements> ls --hyperlink=always example.py | xxd
    00000000: 1b5d 383b 3b66 696c 653a 2f2f 7065 6e67  .]8;;file://peng
    00000010: 7569 6e2f 686f 6d65 2f61 6c65 7867 6179  uin/home/alexgay
    00000020: 6e6f 722f 7072 6f6a 6563 7473 2f73 7465  nor/projects/ste
    00000030: 702d 6578 7069 7265 6d65 6e74 732f 6578  p-expirements/ex
    00000040: 616d 706c 652e 7079 0765 7861 6d70 6c65  ample.py.example
    00000050: 2e70 791b 5d38 3b3b 070a                 .py.]8;;..
    

    If ls can have nice things, surely a program as awesome as rg can 😂

  8. saleemrashid commented on Jun 28, 2020

    @saleemrashid

    This is fairly comprehensive documentation on the hyperlink feature that @alex mentioned: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

  9. mx-psi commented on Aug 5, 2020

    @mx-psi

    Any chance this will be reopened? As mentioned above, there is widespread support for hyperlinks on modern terminal emulators and tools like ls have built-in support for this.

  10. kovidgoyal commented on Oct 6, 2020

    @kovidgoyal

    FYI: Here is a wrapper implementation that actually allows you to click on results and open them in your editor at the matched line. https://sw.kovidgoyal.net/kitty/kittens/hyperlinked_grep.html

    Note that it works with the kitty terminal.

  11. adrian-gierakowski commented on Feb 6, 2021

    @adrian-gierakowski

    @BurntSushi would you be so kind and reconsider? it would be amazing to have it supported out of the box and not have to use wrappers

  12. bluss commented on May 13, 2021

    @bluss

    The following things seem to be needed for supporting hyperlinked file paths in ripgrep. I'm just writing for no reason, maybe it's useful.

    • Resolve paths to absolute paths (I would suggest do so without touching the filesystem, don't want canonicalization) and url escape paths to be printable-ascii-safe as file:// URIs.
    • Lookup current hostname (bonus feature but should preferably be in the URL according to the spec, this seems to be a bit of a layer-busting complication)
    • Add cli parameter --hyperlink={always|ansi|auto|never} (I don't know if ansi is useful here, but I think so)
    • Use the hyperlink escapes in the printer crate. I'm not sure if it's a great fit to try to put it inside termcolor - even if the spec says it works very similarly to colors.

    This feature is supported with the same escape code in Linux (various terminals including gnome-terminal), Windows (microsoft/terminal), macos (iTerm2). The pager less supports it in new versions.

  13. BurntSushi commented on May 13, 2021

    @BurntSushi
    Owner

    @bluss Thanks for laying that out! Some quick feedback:

    • If possible, I'd like to avoid the hostname lookup aspect of this. You're spot on about it being layer busting. I think the key thing here is, what does the hostname buy us? i.e., What do we lose if we don't bother with it.
    • Putting this inside of termcolor might be nice to be honest, especially if it's an ANSI escape sequence. Or at least, putting the emission of that ANSI escape inside termcolor would be good. Having it be outside of termcolor would probably be more problematic.
    • When supporting the legacy Windows console, I think we would just not emit the escape sequence, like we do now for things not supported by the Windows console.

    I think that's all I can think of for right now. I'll re-open.

  14. 32 remaining items

  15. 097115 commented on Apr 10, 2023

    @097115

    @ltrzesniewski

    Thanks for your builds!

    However, the hyperlinks seem not to work under tmux (ls still works, though). Tested in kitty and alacritty.

  16. nbenitez commented on Apr 10, 2023

    @nbenitez

    @097115 Excerpt from https://superuser.com/questions/1771573/file-hyperlink-not-working-under-tmux :

    Support for hyperlinks has been added to tmux in Git a few months ago and will be available in the next release, probably 3.4

  17. 097115 commented on Apr 10, 2023

    @097115

    I'm on 3.4 and as I said in my first comment, ls --hyperlink=always does work for me in tmux. While @ltrzesniewski's custom build of rg doesn't.

  18. ltrzesniewski commented on Apr 10, 2023

    @ltrzesniewski
    Contributor

    @097115 thanks for your feedback. I'll take a look.

  19. ltrzesniewski commented on Apr 12, 2023

    @ltrzesniewski
    Contributor

    @097115 I believe this is an issue in tmux, and have reported it here: tmux/tmux#3525

  20. 097115 commented on Apr 13, 2023

    @097115

    Thanks again, Lucas!

  21. BurntSushi commented on Sep 22, 2023

    @BurntSushi
    Owner

    For anyone following this issue, there is active discussion about adding support for it in this PR: #2483

    Opinions are welcome because this is clearly a very thorny feature to add support for. It is not simple and it looks like it is going to be integration specific. I won't be surprised if I get this wrong in some way in the initial release unfortunately.

  22. added a commit that references this issue on Sep 25, 2023
    0fb591c
  23. added a commit that references this issue on Sep 25, 2023
    f608d4d
  24. BurntSushi commented on Sep 25, 2023

    @BurntSushi
    Owner

    Support for hyperlinks is on master. I would love feedback here: #2611

  25. added a commit that references this issue on May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn enhancement to the functionality of the software.questionAn issue that is lacking clarity on one or more points.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions