Skip to content

Instantly share code, notes, and snippets.

@meyt
Created April 14, 2026 12:11
Show Gist options
  • Select an option

  • Save meyt/de86e868a8d893f287efd633d1572ab9 to your computer and use it in GitHub Desktop.

Select an option

Save meyt/de86e868a8d893f287efd633d1572ab9 to your computer and use it in GitHub Desktop.
Retry the command until its done (zsh compatible)
# Retry the command until its done.
# install: put it in .zshrc or .bashrc
# usage:
# untilok rsync ...
# RETRY_DELAY=2 untilok rsync ...
untilok() {
retrydelay=${RETRY_DELAY:-10} # seconds; override by exporting RETRY_DELAY
while true; do
"$@"
cmdstatus=$?
if [[ $cmdstatus -eq 0 ]]; then
echo "✅ Command succeeded."
break
else
echo "⚠️ Command failed with exit code $cmdstatus. Retrying in $retrydelay seconds..."
sleep "$retrydelay"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment