eza-community / eza

A modern, maintained replacement for ls
https://eza.rocks
MIT License
8.76k stars 171 forks source link

feat: Formatted hyperlinks #997

Open 2crayon opened 1 month ago

2crayon commented 1 month ago

Currently the hyperlink format in eza is hardcoded to be file:///{path}, ripgrep has the ability to change this format to whatever you want with some nice aliases https://github.com/BurntSushi/ripgrep/discussions/2611

I would use this to list files in a project with eza --tree and have links always open in my text editor :)

gierens commented 1 month ago

Interesting!

Correct! Eza hardcodes this here: https://github.com/eza-community/eza/blob/bbede6d45398d0d6f5e7eb5cfff4ae4674e6315a/src/output/file_name.rs#L402

I looked at the ripgrep sources and they offer predefined aliases (https://github.com/BurntSushi/ripgrep/blob/f1d23c06e30606b2428a4e32da8f0b5069e81280/crates/printer/src/hyperlink_aliases.rs#L4-L22) and a parser for custom formats (https://github.com/BurntSushi/ripgrep/blob/f1d23c06e30606b2428a4e32da8f0b5069e81280/crates/printer/src/hyperlink.rs#L95-L171).

I think switching between predefined formats via a command line flag should be fairly straight forward to implement. Allowing the user to define a custom format is more involved though and also maybe a bit of overkill since we don't have that many interesting information to pack into a link as ripgrep with lines and colums within files. So we might wanna limit the scope when implementing this.

2crayon commented 1 month ago

I think it would also be useful to be able to have different formats for different file types, so e.g. you could say that directories should open in a file explorer and regular files should open in a text editor.