arp242 / xdg_open.vim

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

Don't prepend 'http://' to paths #5

Closed Julow closed 2 years ago

Julow commented 2 years ago

Closes https://github.com/arp242/xdg_open.vim/issues/1

Xdg-open accepts more than HTTP urls, for example it can open local files in a corresponding native applications or FTP uris.

This is really useful in combination with vim-dirvish, which show the full path of every files (visually hidden).

arp242 commented 2 years ago

Won't this break opening something like example.com?

Julow commented 2 years ago

It will,

xdg-open: file 'example.com' does not exist

Is this really a use case ? example.com looks like a file to me.

My use case is can accommodated with a less intrusive change though. vim-dirvish buffers contain absolute paths, which start with a /. The prefix could be added only if the input doesn't start with a /, instead of currently, if it doesn't contain ://.

arp242 commented 2 years ago

Is this really a use case ? example.com looks like a file to me.

Yeah, I use it like that frequently; for example for Go imports:

import (
    "context"
    "embed"
    "fmt"
    "math"
    "strconv"

    "github.com/google/uuid"
    "github.com/mattn/go-sqlite3"
    "zgo.at/z18n"
    "zgo.at/zdb"
    "zgo.at/zstd/zcrypto"
    "zgo.at/zstd/zint"
    "zgo.at/zvalidate"
)

I can quickly go to e.g. github.com/mattn/go-sqlite3. It sometimes comes up in some Markdown files and the like too.

I think at least xdg_open#open_url() should continue to work like it does currently, but xdg_open#open() can use the literal input (and then maybe also map gX to open_url(), rather than open()).

arp242 commented 2 years ago

I'll make a patch btw

arp242 commented 2 years ago

I updated the master branch, which should solve this issue. See the commit and updated docs: gX always opens an URL, addressing the use-case I mentioned, and gx doesn't add http:// (which seems to work well from Dirvish (as long as <cWORD> matches the path anyway, it breaks if there are spaces – should maybe add an exception for the dirvish filetype).

Julow commented 2 years ago

Thanks!