Skip to content

Instantly share code, notes, and snippets.

@EHfive
Last active February 3, 2023 01:56
Show Gist options
  • Save EHfive/b1db5092faa3a65c2e504fe675cd043b to your computer and use it in GitHub Desktop.
Save EHfive/b1db5092faa3a65c2e504fe675cd043b to your computer and use it in GitHub Desktop.
PipeWire config diff, a helper script for syncing PipeWire config changes from '/usr/share/pipewire' to '/etc/pipewire' or "$XDG_CONFIG_HOME/pipewire"
#!/usr/bin/env bash
DIFFPROG="${DIFFPROG:-vimdiff}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}"
pw_datadir=/usr/share/pipewire
pw_confdir="/etc/pipewire"
#pw_confdir="$XDG_CONFIG_HOME/pipewire"
conf_savedir="$pw_confdir/.pw-conf-diff"
for conf in $(find "$pw_datadir" -name '*.conf' -type f); do
local_conf="$(echo "$conf" | sed -e "s|$pw_datadir|$pw_confdir|")"
prev_conf="$(echo "$conf" | sed -e "s|$pw_datadir|$conf_savedir|")"
cmp_conf="$prev_conf"
if [[ ! -f "$local_conf" ]]; then
continue
fi
if [[ ! -f "$prev_conf" ]]; then
cmp_conf="$local_conf"
fi
if diff "$cmp_conf" "$conf" >/dev/null 2>&1 ; then
continue
fi
while true; do
read -p "${local_conf} (v)iew/(d)one/(s)kip/(q)uit:" action
case $action in
[Vv]*) "$DIFFPROG" "$conf" "$local_conf";;
[Dd]*) install -Dm644 "$conf" "$prev_conf"; break;;
[Ss]*) break;;
[Qq]*) exit;;
* ) echo "Input an action";;
esac
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment