Skip to content

Instantly share code, notes, and snippets.

@ryanartecona
Created December 14, 2012 06:44
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 ryanartecona/4283221 to your computer and use it in GitHub Desktop.
Save ryanartecona/4283221 to your computer and use it in GitHub Desktop.
Add a sanity confirmation to sensitive commands
# with help from
# http://stackoverflow.com/questions/3231804/in-bash-how-to-add-are-you-sure-y-n-to-any-command-or-alias
# and
# http://stackoverflow.com/questions/1537673/how-do-i-forward-parameters-to-other-command-in-bash-script
function confirm( ) {
#confirm with the user
read -r -p "$* [y/n]: " response
case "$response" in
[yY][eE][sS]|[yY])
#if yes, then execute the passed parameters
"$@"
;;
*)
#Otherwise exit...
echo "cancelled."
;;
esac
}
# make sure it works properly
alias ls='confirm ls'
# protect my terminal from myself
alias kill='confirm kill'
alias pkill='confirm pkill'
#etcetera
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment