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

Allow clicking on results in terminal to open folder or file viewer #1563

Closed
schallm opened this issue May 16, 2024 · 5 comments · Fixed by #1571
Closed

Allow clicking on results in terminal to open folder or file viewer #1563

schallm opened this issue May 16, 2024 · 5 comments · Fixed by #1571

Comments

@schallm
Copy link

schallm commented May 16, 2024

Would love to see something similar to ripgrep's new --hyperlink-format option. ( 14.0.0 release ) It so helpful to be able to open matching files and even have it jump line number of matched text. It would be great if fd allowed something similar.

For example:

  • Allowing folders to be opened in the OS's default folder viewer (i.e., Finder, Explorer, ...) with --folder-hyperlink-format default and allowing overrides like the following to open directory a new default shell --folder-hyperlink-format shell
  • File handling could match ripgrep's handler and open the file with the OS's default handler with --file-hyperlink-format default and allow overrides for common tools like vscode with --file-hyperlink-format vscode
tmccombs added a commit to tmccombs/fd that referenced this issue Jun 8, 2024
tmccombs added a commit to tmccombs/fd that referenced this issue Jun 8, 2024
@tmccombs
Copy link
Collaborator

tmccombs commented Jun 8, 2024

This is a duplicate of #1295

@tmccombs tmccombs closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2024
tmccombs added a commit to tmccombs/fd that referenced this issue Jun 8, 2024
tmccombs added a commit to tmccombs/fd that referenced this issue Jun 9, 2024
@dandavison
Copy link

#1571 is a great start, but arguably doesn't fully close this issue: as @schallm suggests in the description of this issue, adopting ripgrep's --hyperlink-format would allow the user to configure the URL that will be emitted, so that for example it will open in common editors/IDEs using their custom protocols. Currently (with #1571) the user would have to configure their OS to route file:// protocol links to the desired application, but that will not have the same behavior in general, and is less powerful (e.g. user cannot pass URL parameters)

@dandavison
Copy link

Moving conversation from PR discussion #1571 (comment):

It's sort of possible to do that today using the --format option. That is, you could do something like:

fd --absolute-path --format $'\e]8;;vscode://file/{}\e\\{}\e]8;;\e\\' ...

Thanks! OK, but there are at least two problems with that (which is probably why you said "sort of possible"):

  1. There's no color
  2. The file path is displayed as absolute, whereas we will usually want relative path displayed, and the absolute path in the hyperlink.

Here's the best I've come up with so far (thanks for showing the $' trick), but this probably has bugs (e.g. spaces in hostname?):

fd() {
    command fd --color=always --hyperlink=always "$@" |
        rg -r $'\e]8;;vscode://file$1' $'^\e]8;;file://'$(hostname)'(.*)'
}

Some examples of editors/IDEs supporting custom protocols I'm aware of are

  • vscode
  • pycharm, intelliJ, webstorm and presumably other JetBrains IDEs
  • zed

But I imagine there are others. Definitely understand opting for a simple initial implementation but given fd's role of "display paths in terminal for user to do things with", I suspect fd will want to do this ultimately.

So I guess the main question is forwards-compatibility. Seems like e.g. fd --hyperlink=vscode would be natural, convenient, and would work fine with the current always|never|auto enum.

And then for a fully custom protocol / URL format, --format would sort of do it -- sorry if I missed it but where's the documentation of the --format template? Would it make sense for it to support both {absolute-path} and {relative-path} placeholders? Alternatively --hyperlink-format might make it much easier for users to retain fd's coloring.

@tmccombs
Copy link
Collaborator

Could we open a new issue for this?

@dandavison
Copy link

Absolutely. #1597

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

Successfully merging a pull request may close this issue.

3 participants