#!/usr/bin/env nix-shell
#!nix-shell -i bash -p dconf2nix sd nixfmt
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"

dump() {
  ROOT="$1"
  shift
  dconf dump "/$ROOT/" \
    | sd '^\[([^/])' "[$ROOT/\$1" \
    | sd '^\[/\]$' "[$ROOT]"
}
dump1() {
  dump "$@" | sed -e '/^$/,$d'
}

{
  dump "org/gnome/desktop/input-sources"
  dump "org/gnome/desktop/peripherals/touchpad"
  dump "org/gnome/desktop/wm/keybindings"
  dump "org/gnome/mutter/keybindings"
  dump "org/gnome/shell/keybindings"
  dump "org/gnome/settings-daemon/plugins/media-keys"
  # dump "org/gnome/desktop/notifications/application/emote"
} | dconf2nix > dconf-gnome-bindings.nix

{
  #dump "org/gnome/shell"
  dump "org/gnome/shell/extensions/vertical-workspaces"
  #dump "org/gnome/shell/extensions/vertical-overview"
  dump "org/gnome/shell/extensions/big-avatar"
  dump "org/gnome/shell/extensions/gtile"
  dump "org/gnome/shell/extensions/just-perfection"
  dump "org/gnome/shell/extensions/pip-on-top"
} | dconf2nix > dconf-gnome-extensions.nix

{
  dump "org/gnome/desktop/search-providers"
  dump1 "org/gnome/mutter"
  dump "org/freedesktop/tracker/miner/files"
} | dconf2nix > dconf-gnome-behaviour.nix

{
  dump "org/gnome/shell/extensions/user-theme"
  dump "org/gnome/desktop/interface" # features stuff already set by home-manager
  dump "org/gnome/desktop/wm/preferences"
  dump "org/gnome/shell/overrides"
  dump "org/gnome/tweaks"
  # dump1 "org/gnome/mutter"
  dump "org/gnome/desktop/calendar"
  dump "org/gnome/desktop/privacy"
} | dconf2nix | sd --string-mode \
  '"/org/gnome/desktop/interface" = {' \
  '"/org/gnome/desktop/interface" = lib.mkDefault {' \
 > dconf-gnome-theme.nix

nixfmt dconf-gnome-bindings.nix
nixfmt dconf-gnome-extensions.nix
nixfmt dconf-gnome-theme.nix
nixfmt dconf-gnome-behaviour.nix
