Skip to content

πŸ πŸ”§ A BASH script to move dot-folders from/to xdg paths before and after execution

Notifications You must be signed in to change notification settings

polirritmico/force-xdg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Force-XDG πŸ πŸ”§

GitHub last commit License: GPL v3

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.

Force-XDG running

TL;DR

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

Description

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/.

Example

Alternative: Fake Home Mode

$ 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.

Installation

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

Usage

First run:

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.

Fake Home Mode

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;

With KDE:

Force-XDG works great with KDE, simply edit the program launcher and use the -k option:

  1. Open the KDE main menu.
  2. Find the program β†’ Right click β†’ "Edit application" β†’ Application tab.
  3. In the Command section, add force-xdg -k before the binary call.
  4. If necesary add escaped quotes to the place holder: %F β†’ \"%F\" (see the example).
  5. Save.
  6. Launch the program from the KDE menu or Krunner.
  7. Close the program.
  8. 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\"

Config app launcher through kmenuedit screenshot

Done!

About

πŸ πŸ”§ A BASH script to move dot-folders from/to xdg paths before and after execution

Resources

Stars

Watchers

Forks