Sat, 20 Jul 2019 17:37:48 +0200
Better plumbing in Xorg with plan9port's plumber
Well, this phlog was supposed to be about philosophy, but, well having not dicussed what is philosophy, I am free to write about any topic I want. Radical freedom!
As we all know, the normal "plumbing" we experience in modern Xorg desktop enviroments is usually the xdg-open. It contains all the artful elements of FreeDesktop code, including the lack of knowledge what actually does and 20 ways of configuring, all of them barely working.
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 stresed about it.
To, use it, we should first install plan9port, and setup the enviroment variable PLAN9 to the location of plan9port, in gentoo it is
/usr/lib/plan9port and adding
$PLAN9/bin to our
$PATH. 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 $PLAN9/plumb/ to your own `$HOME/lib`. The configuration is very clear and easy to use, as all the actions can be done using regular expresions, therefore we have easy understanding of which rule does.
To update the configuration, without restart the plumber, we invoke
9p write plumb/rules < $HOME/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 $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.