xfconf-query save and load from file
xfconf-query load from file
Introduction
The wonderful xfce desktop environment provides a mechanism to inspect and modify your settings, similar to dconf. This tool is named xfconf-query, and it allows you to list and modify entries one at a time. Unfortunately, it does not provide a way to export to a file and import, the way dconf does (with standard redirection).
Save settings to file For xfce, you can display the settings by specifying
the channel:
xfconf-query -c thunar -lv
place sample output here You can save this to a file with output redirection,
but you won't be able to load this very easily from such a file. To get the settings in a nicer format for saving to a text file, use this oneliner:
xfconf-query -l | sed -r -e '/Channels:/d' | while read line; do xfconf-query -lv -c "${line}" | sed -r -e "s/^/${line} /"; done > my-settings.xfconf
place sample output here
xfconf-query load settings from file
I wrote a wrapper script that loads the settings from such a file. Please check out the full xfconf.sh script at gitlab. Its basic use is very simple. Call the script with the settings file as the only parameter:
xfconf.sh mysettings.xfconf
Code walkthrough
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
The line numbers here are different from the script on github, and probably will get outdated as I make improvements to this utility. So I will use line numbers for the version seen above. Also, this script was originally written as a small portion of a larger project to deploy my settings to a whole system. That's why you'll see the "sudo - su" and logic to determine file ownership, because it is being called by a command running with sudo. Lines 23-31 find the running desktop environment for the user (or the user who called sudo) and grab the values for DBUS_SESSION_BUS_ADDRESS and DISPLAY that point to that running desktop environment. I don't know a more official way, so I assembled this kludge over the course of this project. I'm rather fond of this logic despite the kludgeyness. You will observe on line 30 that this script actually dot sources a temp file with those variables. I actually first used this technique for loading conf files in an attempt to be more unix-like and use environment variables first, and then load in a conf file. Line 34 calculates the requested file has contents, and the desktop environment really exists and is running, and one of the variables from the previous section is defined. Lines 42-58 perform the actual import of settings from the file. The interesting regular expression is my official non-blank non- comment regex. For quick hand-typed oneliners, I normally just use '^$|^#' but here I went with the fancier version that handles whitespace. So the block reads three entries per line, the channel, item, and item value. Then it runs xfconf-query and plugs in the variable. Lines 48-53 perform a manual type declaration based on hard-coded names. I don't know how to query that from xfconf-query, so I had to use the graphical xfce settings tool to collect the exact names. You will definitely need to read through your xfconf files to make sure you include all the right options here. I suppose one could find a list of all the datatypes maybe from xfce's documentation and parse it. I guess I'll add that to the "Improve:" header.
Comments