dotfiles/.local/bin/dconf-load

84 lines
1.6 KiB
Text
Raw Normal View History

2026-08-03 14:30:55 +02:00
#!/bin/sh
# Load the ~/.config/gnome-settings[/local]/*.ini files into `dconf`,
# or just the single <file> given as an argument
#
# Unlike ~/.local/bin/gnome-restore this neither backs up nor resets
# anything, so keys removed from the *.ini files stay active
# => Use this for a quick iteration on the *.ini files,
# and `gnome-restore` for a deterministic state
set -eu
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
GNOME_CFG_DIR="$XDG_CONFIG_HOME/gnome-settings"
_usage() {
echo "Usage: $(basename "$0") [<file>]" >&2
exit 1
}
_load() {
# The *.ini files are machine independent and use a placeholder /home/user
echo " $(basename "$1")"
sed "s|/home/user|$HOME|g" "$1" | dconf load /
}
if ! command -v dconf >/dev/null 2>&1; then
echo "dconf is not installed" >&2
exit 1
fi
[ "$#" -le 1 ] || _usage
# A single file, e.g., while iterating on it
if [ "$#" -eq 1 ]; then
if [ ! -f "$1" ]; then
echo "No such file: $1" >&2
exit 1
fi
echo "Loading a single GNOME settings file:"
_load "$1"
exit 0
fi
# Load all *.ini files in ~/.config/gnome-settings[/local]/
if [ ! -d "$GNOME_CFG_DIR" ]; then
echo "No such directory: $GNOME_CFG_DIR" >&2
exit 1
fi
echo "Loading GNOME settings from: $GNOME_CFG_DIR"
for file in "$GNOME_CFG_DIR"/*.ini; do
[ -e "$file" ] || continue # because the glob does not expand if empty
_load "$file"
done
for file in "$GNOME_CFG_DIR"/local/*.ini; do
[ -e "$file" ] || continue # because the glob does not expand if empty
_load "$file"
done