arp242 / xdg_open.vim

Run xdg-open from Vim; re-implements netrw's gx.
MIT License
11 stars 4 forks source link

plugin: add support for local files and remove open_url. #3

Closed averms closed 2 years ago

averms commented 3 years ago

We can now open local files and URLs to websites. Remove open_url because it isn't necessary when both local files and URLs are supported.


If people depend on open_url and we want to keep that, let me know and I'll bring it back

arp242 commented 3 years ago

Thanks, not sure how I missed your PRs, sorry about that 😅

With "local files" I assume you mean a path like /home/martin/file.png or some such, and xdg-open will open that with GIMP or whatnot?

I can see how that's useful; my own use case for this is just to open URLs, and I rather like how it displays an error if something isn't an URL. This is a lot clearer than simply nothing happening.

For example, something I ran in do today is opening the line:

d, err := fetch("https://raw.githubusercontent.com/unicode-org/cldr/master/common/annotations/en.xml")

And pressing gx will try to open fetch("....") as an URL, which obviously isn't right.

I wonder if we can't just use the return code from xdg-open though, since:

$ xdg-open 'fetch("https://raw.githubusercontent.com/unicode-org/cldr/master/common/annotations/en.xml")'
xdg-open: file 'fetch("https://raw.githubusercontent.com/unicode-org/cldr/master/common/annotations/en.xml")' does not exist

$ echo $? 2

But the problem is that this:

$ xdg-open file.unknown

Will actually open file.unknown in Firefox :-/ That's probably why I added the check like this, I have dim memories of running in to this.

Need to think a bit about what makes the most sense for all of this 🤔

averms commented 2 years ago

And pressing gx will try to open fetch("....") as an URL, which obviously isn't right.

Yeah it's hard to find a good g:xdg_open_match that works for all URLs, let alone all files. I wish there was a way to specify a regex.

Anyway, I've made a fork which has a modified version of this patch so I'll close this.