A BASH script to force non-compliant XDG Base Directory programs to store
their hidden dot folders and files in the XDG Data path instead of polluting
$HOME
.
Just call the script with the program and its args or paths:
$ force-xdg program --example -n options "/path/to/file"
It will store the dot folders/files inside $XDG_DATA_HOME/Force-XDG/program/
.
For help:
$ force-xdg -h
When the program is launched, the script will move the content of the
$XDG_DATA_HOME/Force-XDG/program/
folder into $HOME
and after closing it
will move the folders and files back to $XDG_DATA_HOME/Force-XDG/program/
.
Moving files on the same filesystem in GNU/Linux is really fast since only the directory entries are modified.
For example if Steam is launched through Force-XDG:
$ force-xdg steam
It will move from ~/.local/share/Force-XDG/steam/
the folders and files
pki/
, steam/
, steampath
and steampid
to ~/.pki
, ~/.steam
,
~/.steampath
and ~/.steampid
accordingly. After Steam is closed, it
will move those elements back to ~/.local/share/Force-XDG/steam/
.
$ force-xdg -f steam
In this mode instead of getting the file list and move dirs and files, the
script will simply change the $HOME
environment variable value to
$XDG_DATA_HOME/Force-XDG/fake_home
so all dirs and folders are generated and
stored on that folder.
Just copy the script to ~/.local/bin/
, /usr/local/bin/
or any location in
your PATH
. As an alternative make install
can be used to do it automatically
to ~/.local/bin/
. This also install a BASH auto-completion entry in
XDG_DATA_HOME/bash-completion/completions
):
git clone https://github.com/polirritmico/force-xdg.git
make install
When the program is run through Force-XDG for the first time, the script will
read the state of the dot folders and files of home and compare it with the
state after closing the program, then it will store the list of new folders and
files into $XDG_DATA_HOME/Force-XDG/db
.
For example, lets see the files of Steam stored in the db:
$ cat ~/.local/share/Force-XDG/db | grep steam
steam;steampid;steampath;steam;pki;
Is strongly recommended to close the program as soon as posible on its first run to get a clean file list as any dot-folder or file generated while the program is running for first time will be added to the program's list.
Sets the $HOME
env value to $XDG_DATA_HOME/Force-XDG/fake_home
. The script
will also store the fake home option on the database so no further -f
arg
calls are needed.
First run:
$ force-xdg -f PROGRAM
Then -f
is no longer needed:
$ force-xdg PROGRAM
$ cat $XDG_DATA_HOME/Force-XDG/db | grep PROGRAM
PROGRAM;FAKEHOME;
Force-XDG works great with KDE, simply edit the program launcher and use the
-k
option:
- Open the KDE main menu.
- Find the program β Right click β "Edit application" β Application tab.
- In the Command section, add force-xdg -k before the binary call.
- If necesary add escaped quotes to the place holder:
%F
β\"%F\"
(see the example). - Save.
- Launch the program from the KDE menu or Krunner.
- Close the program.
- Enjoy a clean home folder.
For example let's configure Audacity:
On kmenuedit
, search for "Audacity" and click on the proper result. The
command section should read something like this:
env UBUNTU_MENUPROXY=0 audacity %F
It has a "env variable" (most launchers don't have that), then the program, and finally a "place holder". Simply adding force-xdg before the command and escaped quotes to the "place holder" will do the trick:
env UBUNTU_MENUPROXY=0 force-xdg -k audacity \"%F\"
Done!