Skip to content

Instantly share code, notes, and snippets.

@WGH-
Created November 2, 2023 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WGH-/732193e083cccc5b78d690ab506d1c94 to your computer and use it in GitHub Desktop.
Save WGH-/732193e083cccc5b78d690ab506d1c94 to your computer and use it in GitHub Desktop.
Weird flex: pv that reports its progress to systemd (needs NotifyAccess=all), e.g. for backup scripts
pv-systemd-notify() {
if [[ -v NOTIFY_SOCKET ]]; then
local f
function f {
stdbuf -oL tr '\r' '\n' | while IFS= read -r; do
systemd-notify --status="$REPLY"
done
}
pv -f 2> >(f) "$@"
else
pv "$@"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment