Better plumbing in Xorg with plan9port's plumber

03/21/2021 04:48:56 PM

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 is /usr/lib/plan9port and adding /usr/lib/plan9/bin to our /home/lich/bin:/home/lich/bin/games:/home/lich/bin/jre:/home/lich/.local/bin:/home/lich/.local/go/bin:/usr/condabin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/plan9/bin. Then 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 the fileaddr file from the /usr/lib/plan9/plumb/ to your own /home/lich/lib. The 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.

Enjoyed the article? Please consider donating. Thanks.

Back to the index