Skip to content

Instantly share code, notes, and snippets.

@blizzrdof77
Forked from termnml/gnome3_keybind_backup.sh
Last active May 12, 2025 19:33
Show Gist options
  • Save blizzrdof77/74e3d94b7bf89c89ec9201773d7246fb to your computer and use it in GitHub Desktop.
Save blizzrdof77/74e3d94b7bf89c89ec9201773d7246fb to your computer and use it in GitHub Desktop.
Backs up and restores gnome3 keybindings
#!/usr/bin/env bash
# Backs up and restores gnome3 keybindings
# Tested with Gnome 3.36.8
# by @peterrus, revisions by @blizzrdof77
set -e
# set -x
SCRIPT_NAME=$(basename "$0")
if [[ "$1" == "--help" || "$1" = "-h" || -z "$1" ]]; then
echo "USAGE: $SCRIPT_NAME <backup|restore>"
exit 0
fi
mkdir -p gnome3-keybind-backup
if [[ $1 == 'backup' ]]; then
dconf dump '/org/gnome/desktop/wm/keybindings/' > gnome3-keybind-backup/keybindings.dconf
dconf dump '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/' > gnome3-keybind-backup/custom-values.dconf
dconf read '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings' > gnome3-keybind-backup/custom-keys.dconf
dconf dump '/org/gnome/shell/keybindings/' > gnome3-keybind-backup/shell-keybindings.dconf
dconf dump '/org/gnome/mutter/keybindings/' > gnome3-keybind-backup/mutter-keybindings.dconf
dconf dump '/org/gnome/mutter/wayland/keybindings/' > gnome3-keybind-backup/mutter-wayland-keybindings.dconf
echo "backup done"
exit 0
fi
if [[ $1 == 'restore' ]]; then
if [[ -z "$2" ]]; then
restore_from="${PWD}/gnome3-keybind-backup"
else
restore_from="$2"
fi
dconf reset -f '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/'
dconf load '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/' < "$restore_from/custom-values.dconf"
dconf write '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings' "$(cat \"$restore_from/custom-keys.dconf\")"
dconf reset -f '/org/gnome/desktop/wm/keybindings/'
dconf load '/org/gnome/desktop/wm/keybindings/' < "$restore_from/keybindings.dconf"
dconf reset -f '/org/gnome/shell/keybindings/'
dconf load '/org/gnome/shell/keybindings/' < "$restore_from/shell-keybindings.dconf"
dconf reset -f '/org/gnome/mutter/keybindings/'
dconf load '/org/gnome/mutter/keybindings/' < "$restore_from/mutter-keybindings.dconf"
dconf reset -f '/org/gnome/mutter/wayland/keybindings/'
dconf load '/org/gnome/mutter/wayland/keybindings/' < "$restore_from/mutter-wayland-keybindings.dconf"
echo "restore done"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment