axieax / urlview.nvim

🔎 Neovim plugin for viewing all the URLs in a buffer
MIT License
231 stars 5 forks source link

Added ability to open URLs without netrw #7

Closed smithbm2316 closed 2 years ago

smithbm2316 commented 2 years ago

Thanks for the awesome plugin! I just put together a small suggestion that allows people like myself who turn netrw off in their config to still be able to use this plugin. It uses the open (MacOS) or xdg-open (Linux/FreeBSD) system command to launch the URLs in the default browser for http/https links. Feel free to disregard though if you're not interested in supporting these, this is just my preferred way of launching URLs 🙂

P.S. - please do not mind the force-pushes, I kept forgetting that my Neovim auto-formats Lua code differently than the standard that this plugin currently uses 🙃

axieax commented 2 years ago

Looks good! Thanks for the feature :D

axieax commented 2 years ago

oops I misclicked <CR> instead of <R-Shift> in that commit message.. 😅

smithbm2316 commented 2 years ago

You're welcome, and thank you again for your work on this plugin! I've been meaning to basically write this plugin myself for months, so you saved me the time by only having to write a few lines of code to not use Netrw in this PR. Everyone wins 😄

axieax commented 2 years ago

That's amazing to hear! My idea is to make this plugin quite extensible - now supporting more and more contexts to search from :))

axieax commented 2 years ago

@smithbm2316 actually now that I think about it, open / xdg-open requires one to specify the https?:// protocol, which some links do not have..

smithbm2316 commented 2 years ago

@smithbm2316 actually now that I think about it, open / xdg-open requires one to specify the https?:// protocol, which some links do not have..

Oh you might be right. I can look into implementing that later today in another PR. Shouldn't be too hard to match if a url starts with that and prepend with https if necessary.

axieax commented 2 years ago

ahaha I had addressed this case in my first commit with a default prefix. Probably good to add something like that back (just realised that netrw needs it as well oops).

I can look into implementing that later today in another PR

Thanks that would be amazing! Should be quite trivial by adding it to this line 😍😍

smithbm2316 commented 2 years ago

Yeah I can probably hack something together after work tonight. Do you want me to do a global check for https:// or just check in the M.navigate_url() function specifically in the code for the open/xdg-open functionality? I was just gonna toss a check into that so it didn't effect the Netrw part of the code, but if you want to do a global check we could maybe open a bigger PR to look into supporting multiple prefixes that would be necessary. But I can easily toss up a quick and dirty solution to this for the xdg-open/open situation tonight no problem if you wanna just do that for now. let me know!

In this PR i basically just searched the files for the function that executes the netrw function and added the xdg-open/open code there, i really did not read anything else in the codebase yet 😆

axieax commented 2 years ago

It seems to also be an issue for the netrw stuff, so probably a general one (which can be resolved by injecting a prefix into the www... capture in search.content. The other captures should contain the required protocol so it should be good!

smithbm2316 commented 2 years ago

Cool, thanks for the info. Apologies, I ended up having a busier couple of days than i anticipated. Will take a look at implementing this over the weekend!

axieax commented 2 years ago

That's all g! Idm taking it either :))