One answer that has not come up yet, is using Linux’s binfmt_misc
capabilities, to create a native executable link format that works on the kernel level!
To automatically open any .link
files in xdg-open
, put this inside an executable file at /etc/local.d/binfmt_misc.start
, or any file your OS runs on startup:
#! /bin/sh
echo ':open-hyperlink:E::link::/usr/local/bin/open-hyperlink:' > /proc/sys/fs/binfmt_misc/register
and put the following into the /usr/local/bin/open-hyperlink
executable:
#! /bin/sh
xdg-open "`cat "$1"`"
After that, you can just “run” .link
files that are marked as executable via any means, and it will open the link in the browser. Command line, GUI double click, whatever you like.
$ echo 'http://superuser.com/questions/986527/how-to-create-a-hyperlink-file' > this-page.link
$ chmod +x this-page.link
$ ./this-page.link
[Browser opens…]
You can of course change the extension and file format how you like, provided you change the open-hyperlink
script accordingly. Even Windows .lnk
files!
Of course your kernel has to have that module available and enabled, for it to work. (I have it compiled in.)
Check out the documentation on binfmt_misc
, as there are a lot more possibilities, e.g. with matching on a pattern instead of a file extension.
<meta>
redirection in it.