Skip to content

Instantly share code, notes, and snippets.

@juanibiapina
Created February 21, 2018 11:29
Show Gist options
  • Save juanibiapina/88ce944af3608be95f203b5095617988 to your computer and use it in GitHub Desktop.
Save juanibiapina/88ce944af3608be95f203b5095617988 to your computer and use it in GitHub Desktop.
Helper command to ask for confirmation before running another command (with pipe support)
#!/usr/bin/env bash
cr=`echo $'\n.'`
cr=${cr%.}
read -p "Do you want to run $*? [N/y]${cr}${cr}" -s -N 1 REPLY
if test "$REPLY" = "y" -o "$REPLY" = "Y"; then
exec "$@"
else
>&2 echo "Cancelled by user"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment