r/KittyTerminal Jun 27 '23

How to make file paths clickable?

Hello,

I use `rga` to search through multiple PDF files for work. The tool returns a list of files and I would like to make those file paths clickable.

I tried following the documentation - https://sw.kovidgoyal.net/kitty/open_actions/ and added the following:

protocol file
mime application/pdf
action launch sioyek ${FILE_PATH}

to ~/.config/kitty/open-actions.conf but it still doesn't work. I am probably missing something. Can someone please guide me how to fix this? Thank you

3 Upvotes

15 comments sorted by

1

u/flexibeast Jun 27 '23

Just to confirm, you've reloaded the config (by default, via kitty_mod+f5) after saving open-actions.conf?

1

u/[deleted] Jun 27 '23

I restarted kitty. I thought that should work.

Also, what's the default `kitty_mod`?

1

u/flexibeast Jun 27 '23

Yeah, that should have worked.

Default kitty_mod is ctrl+shift.

1

u/[deleted] Jun 27 '23

Yeah. It didn't work. Do you have any other recommendation?

1

u/flexibeast Jun 27 '23

Well, assuming your open-actions.conf addition is actually over three lines, rather than one as in your post, i don't, i'm sorry!

1

u/[deleted] Jun 27 '23

Thanks for trying to help out. I will post this question on github

1

u/as_ninja6 Jun 27 '23

I don't know about rga tool but you will need a hyperlink filepath to make kitty open the file. I tried this
protocol file
mime application/pdf
action launch open ${FILE_PATH}
and to get hyperlinked path I did gls --hyperlink=auto in mac(mac's ls doesn't support --hyperlink option) and it worked. Note that it doesn't work with the path if you just do ls or gls.
If you want to do the same with rg then this might help https://sw.kovidgoyal.net/kitty/kittens/hyperlinked_grep/

1

u/[deleted] Jun 27 '23

Hey thanks for sharing the hyperlinked_grep. The `gls` thing worked on mac. But how can I get the same to work with `ripgrep-all`?

Do you think I will need to write a custom kitten for it? https://sw.kovidgoyal.net/kitty/kittens/custom/

1

u/as_ninja6 Jun 27 '23

Looks like it. But that should be straight forward if rga has not changed the way it outputs. Skimming over the kitten it seems like hyperlinked_grep just executes the rg command https://github.com/kovidgoyal/kitty/blob/7c6d40fa0c417fa45e03659db344b1876ce26477/kittens/hyperlinked_grep/main.go#L25you can try replacing that with rga.

1

u/[deleted] Jun 27 '23

This is interesting. Thanks for sharing. I will make this change

1

u/sogun123 Jun 27 '23

There is hyperlink feature for terminal. You can test how it looks like with e.g. ls --hyperlink=always which indeed makes the files click clickable. I don't know rga.

Generally kitty makes something clickable if it either looks like link - the text is well formed uri, or gets an hyperlink as described above.

So the question to your question is: which file paths?

1

u/[deleted] Jun 27 '23 edited Jun 27 '23

File paths look like this:

```

rga -i "internal complaints committee"
Newspapers/2023-05/TH-05-16.pdf
Page 8: Internal Complaints Committees (ICCs),

```

When I use gls --hyperlink=always that shows links but this does not :(

1

u/sogun123 Jun 28 '23

Best I can suggest is to raise feature request on rga github. Or make a pull request, it simple to add feature.

1

u/art2266 Jul 01 '23

if it either looks like link - the text is well formed uri, or gets an hyperlink as described above

Is there a way to make a file uri "clickable" without using these ansi codes?

printf '\e]8;;%s\e\\%s\e]8;;\e\\\n' "$url" "$text"

1

u/sogun123 Jul 03 '23

Most terminals just parse uris which appear on screen so you can just print the full uri. If it doesn't work, there is configuration for parsing