Setting environment variables for KDE's Plasma
I have been a Desktop linux user at the latest since 2005 (I signed up for the Gentoo Forums on 2005-01-26). Almost 19 years now. But you never stop to learn ;-)
I recently adepted that you you could get KDE's native file dialogs using Firefox (instead of those GTK abominations) by using xdg-desktop-portal, along with KDE's backend implementation xdg-desktop-portal-kde. The only thing to do is having those packages installed and setting the environment variable GTK_USE_PORTAL
to 1
.
So … how do we achieve this?! For a console, I would put export GTK_USE_PORTAL=1
to ~/.bashrc. This will work for an opened terminal I type firefox in. But the KDE desktop won't care about this. I had been bugged for KRunner not respecting my custom $PATH
since ever … Plasma won't adopt this export as well.
What do we do? Mess with Firefox's .desktop file? That will be overwritten by the next update. Create a custom startup script that does something like GTK_USE_PORTAL=1 firefox
? That sucks. No! We set the environment variable for Plasma!
That is surprisingly easy. One only has to find the correct docs about this. TL;DR: Every script inside ~/.config/plasma-workspace/env/ will be executed at Plasma's startup. Thus, we simply export our GTK_USE_PORTAL
there. I now use the following script, which lives in ~/.config/plasma-workspace/env/exports.sh:
#!/bin/bash export PATH="/home/tobias/bin:/home/tobias/.local/bin:$PATH" export GTK_USE_PORTAL=1
This does not only make Firefox show native file dialogs, it also adds my custom $PATH
to e.g. KRunner.
Now you know ;-)