๐Ÿ’พ Archived View for bbs.geminispace.org โ€บ u โ€บ clseibold โ€บ 11937 captured on 2023-12-28 at 16:49:06. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Comment by ๐Ÿš€ clseibold

Re: "How to open files and URLs with the preferred application..."

In: s/Gemini

@sloum I never thought about detecting the OS with an environment variable. Usually I do it with compile-time statements (Odin's `when ODIN_OS == .Windows {`), or with the language's runtime variables (I think Golang does it this way).

๐Ÿš€ clseibold

Nov 22 ยท 5 weeks ago

4 Later Comments โ†“

๐Ÿš€ clseibold ยท Nov 22 at 08:03:

@mediocregopher I believe gnome-open is also a thing, but I am not experienced in doing that type of stuff in linux, so I don't know much about it, lol. Xdg-open is very common in linux, so it's probably just fine to use it. Don't mind my bitterness towards linux too much, I just hate that Unix's potential went to waste with Linux's unstandardized and frantic approach :D

Update: Apparently xdg-open is just a wrapper around multiple desktop environments, including gnome-open and `gio open`. Does anyone know if xdg-open requires a DE to work, or if it also works in terminal-only environments?

Update 2: I've also found an exo-open which is the gnome-open equivalent for XFCE. KDE uses kde-open. All three (exo-open, kde-open, and gio) are wrapped with xdg-open.

๐Ÿ‘ป mediocregopher ยท Nov 22 at 08:37:

@clseibold thank you for doing my research for me :) I'll remain contented with xdg-open then.

re: working in a terminal-only environment, I can't think one would.... what the behavior even be? Run a process as a background job in the current shell?

๐Ÿš€ clseibold ยท Nov 22 at 09:32:

@mediocregopher Personally, I would expect that a system where you can specify default applications for different filetypes and URIs be standardized in the OS APIs, and that a cli `open` command would call out to this API and open the file/URI with that default application as a subprocess of the shell. I believe this is essentially what macOS does (macOS does have an `open` command), and it's also what Windows does, and Haiku afaik. Because it would be a part of the OS, it would work in a terminal-only environment and a graphical environment, and there'd be one standard across all variants/extensions of the OS.

๐ŸŒฒ sloum ยท Nov 22 at 21:15:

@clseibold Yes, most languages will have some module for OS detection. You can check against `$OSTYPE`, which I believe should be available for pretty much every major system. Subprocessing out to `uname` can also be useful for this purpose. I can't remember which I did... my use case was in a makefile (for gnu make, since bsd make does not support if statements). So I think it makes sense in a makefile (again, targeting a non-bsd system) but may not have the same use case in a more full featured language/environment.

Original Post

๐ŸŒ’ s/Gemini

How to open files and URLs with the preferred application in multiple operating systems? Not really related to Gemini, but I need to implement a way in my Gemini client to open unsupported URLs and files on their proper apps, mostly on Linux but ideally in other systems as well. Fellows who have written their own clients, how did you do it?

๐Ÿ’ฌ lufte ยท 15 comments ยท Nov 21 ยท 5 weeks ago