0

I am often inadvertently trying to open incomplete filenames with xdg-open, because of the presence of several files with the same basename but different extensions, e.g. very-long-filename.tex, very-long-filename.pdf etc. Using autocomplete in terminal gives me

xdg-open very-long-filename.

and I hit return before checking the name is complete. Instead of an error, this launches my web browser and attempts to open the URL http://very-long-filename./, which is a nuisance.

I never use xdg-open to open URLs from terminal. Is it possible to block xdg-open from opening URLs from terminal if they don't explicitly contain http:// or https:// (or at all), without compromising other URL-opening strategies used by the OS (Ubuntu/Kubuntu)?

I looked at xdg-settings and xdg-mime but the doc is not very exhaustive and it's not obvious to me that this can be achieved. It's not clear why xdg-open defaults to opening anything that is not a filename as a URL, and what kind of mime-type this is.

  • 1
    I might be spitballing here, but it sounds like it might be something in your ~/.config/mimeapps.list that might be tied to not having an extension to default to web browser. Maybe try renaming the file and try again. – Terrance Oct 24 '23 at 02:25
  • ... or perhaps executing xdg-mime query filetype very-long-filename. would tell us something? – steeldriver Oct 24 '23 at 17:44
  • @Terrance: renaming mimeapps.list didn't help (it attempted to open as an URL in Chrome rather than in Firefox)... @steeldriver: the error message is xdg-mime: file 'very-long-filename.' does not exist. That's part of the problem, I don't see in mime anything that is not a file or not specific. E.g. I see x-scheme-handler/http which is handled by firefox, but why would this be followed without mentioning http in the argument of xdg-open? – armando.sano Oct 25 '23 at 08:12
  • Sounds like a bug in the xdg-open possibly. I guess you can try filing a bug against it by running ubuntu-bug xdg-open or maybe try reinstalling the xdg-utils; sudo apt install --reinstall xdg-utils – Terrance Oct 25 '23 at 13:34
  • @Terrance I tried it on a Live Kubuntu 22.04 USB and the same behaviour occurs, so it's not due to an obscure configuration of mine. Same as well with kde-open. Does it occur on a live Ubuntu too? Reinstalling xdg-utils doesn't help either. I'll file a bug at xdg-utils, though it might be a feature rather than a bug. Thanks again for your help. – armando.sano Oct 27 '23 at 07:41
  • I guess it could be a feature of KDE then, but that is very strange. I use Xubuntu 22.04 and it definitely gives me an error of unable to open whatever file I am trying when not specifying a file extension when it has one. – Terrance Oct 27 '23 at 13:49

0 Answers0