Clean way to temporarily replace a config file

configurationfilesinkscapenamespacescripting

I use a drawing program called Inkscape, which has both a GUI and a command line interface. When used on the command line, it has a large number of options that can only be controlled through a user-specific config file, which is hardcoded to be:

$HOME/.config/inkscape/preferences.xml

This config file always contains the options that were most recently used in the GUI, which may be the wrong ones when I'm scripting.

To work around this, I have my script save a copy of the config file, replace it with a standard config file, run the program, and then copy the saved config file back.

This works OK but is not really clean. For example, it won't work properly if two instances of the script are being run concurrently.

On Unix, is there a cleaner way to carry out this task of faking out a program so it takes its config file from someplace that I want, rather than from the pathname hardcoded in the program? Maybe something involving links, or something like BSD jails?

Best Answer

Inkscape has a feature for this as of 0.47:

$ INKSCAPE_PORTABLE_PROFILE_DIR=/some/other/path inkscape --args

Put your script's custom preferences.xml file in /some/other/path. It should be a dedicated directory, because Inkscape will populate it with all the other files it normally puts in ~/.config/Inkscape when you run it like this.

Related Question