As we all know, the normal "plumbing" we experience in modern Xorg desktop environments is usually the xdg-open. It contains all the artful elements of the FreeDesktop code, including the lack of knowledge what it actually does and at least 20 ways of configuring, all of them inconsistent.
Well, replacing xdg-open with your own script is something I also tried, but well, the more rules you want the more chaotic it becomes. And then, I found out that plan9port plumber is perfect for the task.
It operates on something I mentioned - rules. It also has its own version of mimetypes, but they are secondary to rules, and are more of the part of plan9/port ecosystem, so if you do not use acme, you should not be stressed about it.
To, use it, we should first install plan9port, and setup the
environment variable PLAN9 to the location of plan9port, in Gentoo it
/usr/lib/plan9port and adding
/usr/lib/plan9/bin to our
we can start the plumber, by invoking the command
plumber, but it
will not work, as we do not have the configuration.
I would suggest starting with mine configuration (do not forget to copy
fileaddr file from the /usr/lib/plan9/plumb/ to your own
configuration is very clear and easy to use, as all the actions can be
done using regular expressions, therefore we have easy understanding of
which rule does.
To update the configuration, without restart the plumber, we invoke
9p write plumb/rules < /home/lich/lib/plumbing command in order to write
the rules into the 9p port. If we want filesystem access to it, we
have to mount it using
9pfuse $(namespace) /tmp/mnt/plumb. This is
not necessary, but it might make writing scripts easier.
In order to replace the xdg-open "plumber" with plan9port plumber, you can simply link /usr/lib/plan9/bin/plumb, as xdg-open, in your PATH, so it is before the xdg-open. Then all the programs that want to invoke xdg-open will use plumb and you will now what the rules will do.