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

Format results as hyperlinks using common editor protocols and custom protocols #1597

Open
dandavison opened this issue Jul 30, 2024 · 0 comments

Comments

@dandavison
Copy link

It's become common for editors/IDEs to support custom URL file-like protocols, i.e. URL protocols that the OS will respond to by opening the file in the (correct project workspace window of the) application, and perhaps taking some extra actions such as moving the cursor to a coordinate (although this particular action is less relevant for fd). Examples are

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

It would be very nice if fd were to make this convenient.

#1571 has made it possible to render results as terminal hyperlinks while retaining color, and displaying the relative path rather than the absolute path. However, these are currently limited to the traditional file:// protocol, which for many users will not actually open their desired application in the desired manner.

While it is currently possible to construct arbitrary hyperlink results using --format, that currently has a few drawbacks:

  • It would be cumbersome to get nice coloring and to have that coloring match fd's usual color behavior.
  • It's (AIUI) not current possibly to have the relative path displayed; the user would have to see the absolute path.
  • It requires users to set up a rather technical alias or shell wrapper.

This issue is proposing that fd offer new options that overcome these drawbacks. Specifically, the designed solution should satisfy the following:

  1. Convenient to retain fd's coloring
  2. Relative path is displayed, not absolute
  3. User can conveniently construct URLs for popular IDEs/editors

Additionally, it would be ideal to have

  1. User can construct URL with custom protocol, custom URL format, URL parameters

It may be worth noting that a substantial amount of design work (as well as implementation in Rust) was done to address similar goals in BurntSushi/ripgrep#2483.

For context, current workarounds that have been proposed include

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

(fails on color, relative paths, and inconvenience)

and

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

(fails on inconvenience and probably bugs such as hostnames with spaces etc)

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

1 participant