Skip to content

Instantly share code, notes, and snippets.

@EHfive
Last active May 20, 2021
Embed
What would you like to do?
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